From 780266f1df6b31eee171951869e9c2d6269d7a17 Mon Sep 17 00:00:00 2001 From: Jay Klehr Date: Sat, 4 Dec 2021 15:08:41 -0700 Subject: [PATCH] Merge pull request #116 from diablomedia/php-81 testing php 8.1 --- .github/workflows/build.yml | 34 ++++---------- .github/workflows/merge-me.yml | 32 +++++++++++++ .gitignore | 1 + .php_cs => .php-cs-fixer.php | 9 ++-- composer.json | 14 +++--- grumphp.yml.dist | 3 +- phpstan.neon | 60 ++++++++++++++++++++---- phpunit.xml.dist | 30 +++++------- src/Zend/Translate/Adapter.php | 4 +- src/Zend/Translate/Adapter/Csv.php | 2 +- src/Zend/Translate/Adapter/Qt.php | 6 +-- src/Zend/Translate/Adapter/Tbx.php | 3 +- src/Zend/Translate/Adapter/Tmx.php | 2 +- src/Zend/Translate/Adapter/Xliff.php | 3 +- src/Zend/Translate/Adapter/XmlTm.php | 3 +- tests/Zend/Translate/Adapter/IniTest.php | 6 +-- 16 files changed, 129 insertions(+), 83 deletions(-) create mode 100644 .github/workflows/merge-me.yml rename .php_cs => .php-cs-fixer.php (64%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6b65d22..3aeb474 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,21 +13,14 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest] - php-versions: ['7.2', '7.3', '7.4'] + php-versions: ['7.4', '8.0', '8.1'] composer-args: ['', '--prefer-lowest'] - include: - - operating-system: ubuntu-latest - php-versions: '8.0' - composer-args: '--ignore-platform-reqs --no-scripts' - - operating-system: ubuntu-latest - php-versions: '8.0' - composer-args: '--prefer-lowest --ignore-platform-reqs --no-scripts' runs-on: ${{ matrix.operating-system }} steps: - name: Checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.4.0 - name: Setup PHP - uses: shivammathur/setup-php@2.10.0 + uses: shivammathur/setup-php@2.16.0 with: php-version: ${{ matrix.php-versions }} extensions: mbstring @@ -39,7 +32,7 @@ jobs: id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache dependencies - uses: actions/cache@v2.1.4 + uses: actions/cache@v2.1.7 with: path: ${{ steps.composer-cache.outputs.dir }} key: php${{ matrix.php-versions }}-composer-${{ matrix.composer-args }}-${{ hashFiles('**/composer.json') }} @@ -50,21 +43,14 @@ jobs: - name: PHPStan run: composer phpstan - name: Code Style Check + env: + PHP_CS_FIXER_IGNORE_ENV: true run: composer style-check -- --format=checkstyle | cs2pr - name: Test run: composer test-with-coverage - name: Upload Coverage - run: bash <(curl -s https://codecov.io/bash) -f ./clover.xml - merge-me: - name: Merge me! - needs: - - build - runs-on: ubuntu-latest - steps: - - name: Merge me! - uses: ridedott/merge-me-action@master + uses: codecov/codecov-action@v2 with: - # This must be used as GitHub Actions token does not support - # pushing to protected branches. - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_LOGIN: 'dependabot[bot]' + files: ./clover.xml + fail_ci_if_error: true + verbose: true diff --git a/.github/workflows/merge-me.yml b/.github/workflows/merge-me.yml new file mode 100644 index 0000000..c7559ae --- /dev/null +++ b/.github/workflows/merge-me.yml @@ -0,0 +1,32 @@ +name: Merge me! + +on: + workflow_run: + types: + - completed + workflows: + - 'Build' + +jobs: + merge-me: + name: Merge me! + runs-on: ubuntu-latest + steps: + - # It is often a desired behavior to merge only when a workflow execution + # succeeds. This can be changed as needed. + if: ${{ github.event.workflow_run.conclusion == 'success' }} + name: Merge me! + uses: ridedott/merge-me-action@v2 + with: + # Depending on branch protection rules, a manually populated + # `GITHUB_TOKEN_WORKAROUND` secret with permissions to push to + # a protected branch must be used. This secret can have an arbitrary + # name, as an example, this repository uses `DOTTBOTT_TOKEN`. + # + # When using a custom token, it is recommended to leave the following + # comment for other developers to be aware of the reasoning behind it: + # + # This must be used as GitHub Actions token does not support pushing + # to protected branches. + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ENABLE_GITHUB_API_PREVIEW: true diff --git a/.gitignore b/.gitignore index e384fd6..192d02d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /tests/Zend/Translate/Adapter/_files/zend_cache* .php_cs.cache .phpunit.result.cache +.php-cs-fixer.cache diff --git a/.php_cs b/.php-cs-fixer.php similarity index 64% rename from .php_cs rename to .php-cs-fixer.php index e14f877..2ec4112 100644 --- a/.php_cs +++ b/.php-cs-fixer.php @@ -6,17 +6,16 @@ ->in(__DIR__) ; -return PhpCsFixer\Config::create() - ->setRiskyAllowed(true) +$config = new PhpCsFixer\Config(); +return $config->setRiskyAllowed(true) ->setRules(array( '@PSR2' => true, '@PHPUnit60Migration:risky' => true, - '@PHPUnit84Migration:risky' => true, - 'binary_operator_spaces' => array('align_double_arrow' => true, 'align_equals' => true), + 'binary_operator_spaces' => array('operators' => array('=' => 'align', '=>' => 'align')), 'single_quote' => true, 'array_syntax' => array('syntax' => 'long'), 'concat_space' => array('spacing' => 'one'), - 'psr0' => false + 'psr_autoloading' => array('dir' => 'src'), )) ->setUsingCache(true) ->setFinder($finder); diff --git a/composer.json b/composer.json index 90d4ec0..9590e4c 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "homepage": "http://framework.zend.com/", "license": "BSD-3-Clause", "require": { - "php": "^7.0 || ^8.0", + "php": "^7.4 || ~8.0.0 || ~8.1.0", "diablomedia/zendframework1-exception": "^1.0.0", "diablomedia/zendframework1-config": "^1.0.0 || ^2.0.0", "diablomedia/zendframework1-loader": "^1.0.0", @@ -32,11 +32,11 @@ } }, "require-dev": { - "phpunit/phpunit": "^8.5.14 || ^9.0.0", - "phpstan/phpstan": "0.12.82", - "friendsofphp/php-cs-fixer": "2.18.4", - "maglnet/composer-require-checker": "^1.1.0 || ^2.0.0 || ^3.0.0", - "phpro/grumphp-shim": "^0.22.0 || ^1.1" + "phpunit/phpunit": "^9.5.10", + "phpstan/phpstan": "1.2.0", + "friendsofphp/php-cs-fixer": "3.3.2", + "maglnet/composer-require-checker": "^3.0.0", + "phpro/grumphp-shim": "^1.5.0" }, "include-path": [ "src/" @@ -49,7 +49,7 @@ "scripts": { "test": "phpunit", "test-with-coverage": "phpunit --coverage-clover=clover.xml", - "phpstan": "phpstan analyze -c phpstan.neon --no-progress --ansi", + "phpstan": "phpstan analyze -c phpstan.neon --no-progress --ansi --memory-limit=768M", "style-check": "php-cs-fixer fix --dry-run -vv" }, "suggest": { diff --git a/grumphp.yml.dist b/grumphp.yml.dist index 6e05858..0ddc213 100644 --- a/grumphp.yml.dist +++ b/grumphp.yml.dist @@ -7,9 +7,10 @@ grumphp: config_file: require-checker-config.json phpcsfixer2: allow_risky: true - config: .php_cs + config: .php-cs-fixer.php phpstan: configuration: phpstan.neon + memory_limit: 768M phpunit: metadata: priority: 100 diff --git a/phpstan.neon b/phpstan.neon index beaa94b..7c55412 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,7 +3,7 @@ parameters: level: 4 paths: - ./ - excludes_analyse: + excludePaths: - %rootDir%/../../../vendor/* - %rootDir%/../../../tests/* ignoreErrors: @@ -14,15 +14,59 @@ parameters: - '#PHPDoc tag @param references unknown parameter: \$locale#' - '#PHPDoc tag @param references unknown parameter: \$args#' - - message: '#Offset .+ does not exist on array\(.+\)\.#' - path: %currentWorkingDirectory%/src/Zend/Translate/Adapter.php + message: '#Offset .+ does not exist on array{.+}\.#' + path: ./src/Zend/Translate/Adapter.php - - message: '#If condition is always false\.#' - path: %currentWorkingDirectory%/src/Zend/Translate/Adapter.php + message: '#Offset string on array{} in isset\(\) does not exist\.#' + path: ./src/Zend/Translate/Adapter/Array.php - - message: '#Strict comparison using !== between true and true will always evaluate to false\.#' - path: %currentWorkingDirectory%/src/Zend/Translate/Adapter.php + message: '#Offset string on array{} in isset\(\) does not exist\.#' + path: ./src/Zend/Translate/Adapter/Ini.php + - + message: '#Offset .+ on array{.+} in empty\(\) does not exist\.#' + path: ./src/Zend/Translate/Adapter.php # Defensive coding, argument can be multiple types - message: '#Result of \|\| is always true\.#' - path: %currentWorkingDirectory%/src/Zend/Translate/Adapter.php + path: ./src/Zend/Translate/Adapter.php + # These are used through some xml methods + - + message: '#Method Zend_Translate_Adapter_Qt::_startElement\(\) is unused\.#' + path: ./src/Zend/Translate/Adapter/Qt.php + - + message: '#Method Zend_Translate_Adapter_Qt::_endElement\(\) is unused\.#' + path: ./src/Zend/Translate/Adapter/Qt.php + - + message: '#Method Zend_Translate_Adapter_Qt::_contentElement\(\) is unused\.#' + path: ./src/Zend/Translate/Adapter/Qt.php + - + message: '#Method Zend_Translate_Adapter_Tbx::_startElement\(\) is unused\.#' + path: ./src/Zend/Translate/Adapter/Tbx.php + - + message: '#Method Zend_Translate_Adapter_Tbx::_endElement\(\) is unused\.#' + path: ./src/Zend/Translate/Adapter/Tbx.php + - + message: '#Method Zend_Translate_Adapter_Tbx::_contentElement\(\) is unused\.#' + path: ./src/Zend/Translate/Adapter/Tbx.php + - + message: '#Method Zend_Translate_Adapter_Xliff::_startElement\(\) is unused\.#' + path: ./src/Zend/Translate/Adapter/Xliff.php + - + message: '#Method Zend_Translate_Adapter_Xliff::_endElement\(\) is unused\.#' + path: ./src/Zend/Translate/Adapter/Xliff.php + - + message: '#Method Zend_Translate_Adapter_Xliff::_contentElement\(\) is unused\.#' + path: ./src/Zend/Translate/Adapter/Xliff.php + - + message: '#Method Zend_Translate_Adapter_XmlTm::_startElement\(\) is unused\.#' + path: ./src/Zend/Translate/Adapter/XmlTm.php + - + message: '#Method Zend_Translate_Adapter_XmlTm::_endElement\(\) is unused\.#' + path: ./src/Zend/Translate/Adapter/XmlTm.php + - + message: '#Method Zend_Translate_Adapter_XmlTm::_contentElement\(\) is unused\.#' + path: ./src/Zend/Translate/Adapter/XmlTm.php + # This isn't true, there is an empty check on this property in the class + - + message: '#Property Zend_Translate_Adapter_Tmx::\$_useId is never read, only written\.#' + path: ./src/Zend/Translate/Adapter/Tmx.php \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2204d13..d55ddf3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,19 +1,13 @@ - - - - ./tests - - - - - ./src - - + + + + + ./src + + + + + ./tests + + diff --git a/src/Zend/Translate/Adapter.php b/src/Zend/Translate/Adapter.php index 3d13288..cca4381 100644 --- a/src/Zend/Translate/Adapter.php +++ b/src/Zend/Translate/Adapter.php @@ -849,7 +849,7 @@ public function _($messageId, $locale = null) * returns boolean * * @param string|int $messageId Translation string - * @param boolean $original (optional) Allow translation only for original language + * @param boolean|null $original (optional) Allow translation only for original language * when true, a translation for 'en_US' would give false when it can * be translated with 'en' only * @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale identifier, @@ -858,7 +858,7 @@ public function _($messageId, $locale = null) */ public function isTranslated($messageId, $original = false, $locale = null) { - if (($original !== false) and ($original !== true)) { + if (($original !== false) && ($original !== true)) { $locale = $original; $original = false; } diff --git a/src/Zend/Translate/Adapter/Csv.php b/src/Zend/Translate/Adapter/Csv.php index 93d923d..1e63ea7 100644 --- a/src/Zend/Translate/Adapter/Csv.php +++ b/src/Zend/Translate/Adapter/Csv.php @@ -87,7 +87,7 @@ protected function _loadTranslationData($filename, $locale, array $options = arr } while (($data = fgetcsv($this->_file, $options['length'], $options['delimiter'], $options['enclosure'])) !== false) { - if (substr($data[0], 0, 1) === '#') { + if (substr($data[0] ?? '', 0, 1) === '#') { continue; } diff --git a/src/Zend/Translate/Adapter/Qt.php b/src/Zend/Translate/Adapter/Qt.php index 8cc160e..75b5111 100644 --- a/src/Zend/Translate/Adapter/Qt.php +++ b/src/Zend/Translate/Adapter/Qt.php @@ -30,9 +30,6 @@ class Zend_Translate_Adapter_Qt extends Zend_Translate_Adapter { // Internal variables private $_file = false; - private $_cleared = array(); - private $_transunit = null; - private $_source = null; private $_target = null; private $_scontent = null; private $_tcontent = null; @@ -92,7 +89,6 @@ private function _startElement($file, $name, $attrib) { switch (strtolower($name)) { case 'message': - $this->_source = null; $this->_stag = false; $this->_ttag = false; $this->_scontent = null; @@ -142,7 +138,7 @@ private function _contentElement($file, $data) private function _findEncoding($filename) { - $file = file_get_contents($filename, null, null, 0, 100); + $file = file_get_contents($filename, false, null, 0, 100); if (strpos($file, 'encoding') !== false) { $encoding = substr($file, strpos($file, 'encoding') + 9); $encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1); diff --git a/src/Zend/Translate/Adapter/Tbx.php b/src/Zend/Translate/Adapter/Tbx.php index e2bf371..98df4b5 100644 --- a/src/Zend/Translate/Adapter/Tbx.php +++ b/src/Zend/Translate/Adapter/Tbx.php @@ -30,7 +30,6 @@ class Zend_Translate_Adapter_Tbx extends Zend_Translate_Adapter { // Internal variables private $_file = false; - private $_cleared = array(); private $_langset = null; private $_termentry = null; private $_content = null; @@ -147,7 +146,7 @@ private function _contentElement($file, $data) private function _findEncoding($filename) { - $file = file_get_contents($filename, null, null, 0, 100); + $file = file_get_contents($filename, false, null, 0, 100); if (strpos($file, 'encoding') !== false) { $encoding = substr($file, strpos($file, 'encoding') + 9); $encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1); diff --git a/src/Zend/Translate/Adapter/Tmx.php b/src/Zend/Translate/Adapter/Tmx.php index cda8801..c2193c4 100644 --- a/src/Zend/Translate/Adapter/Tmx.php +++ b/src/Zend/Translate/Adapter/Tmx.php @@ -215,7 +215,7 @@ protected function _contentElement($file, $data) */ protected function _findEncoding($filename) { - $file = file_get_contents($filename, null, null, 0, 100); + $file = file_get_contents($filename, false, null, 0, 100); if (strpos($file, 'encoding') !== false) { $encoding = substr($file, strpos($file, 'encoding') + 9); $encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1); diff --git a/src/Zend/Translate/Adapter/Xliff.php b/src/Zend/Translate/Adapter/Xliff.php index e19774d..5fcc5de 100644 --- a/src/Zend/Translate/Adapter/Xliff.php +++ b/src/Zend/Translate/Adapter/Xliff.php @@ -31,7 +31,6 @@ class Zend_Translate_Adapter_Xliff extends Zend_Translate_Adapter // Internal variables private $_file = false; private $_useId = true; - private $_cleared = array(); private $_transunit = null; private $_source = null; private $_target = null; @@ -211,7 +210,7 @@ private function _contentElement($file, $data) private function _findEncoding($filename) { - $file = file_get_contents($filename, null, null, 0, 100); + $file = file_get_contents($filename, false, null, 0, 100); if (strpos($file, 'encoding') !== false) { $encoding = substr($file, strpos($file, 'encoding') + 9); $encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1); diff --git a/src/Zend/Translate/Adapter/XmlTm.php b/src/Zend/Translate/Adapter/XmlTm.php index fbbb11c..af3c0a2 100644 --- a/src/Zend/Translate/Adapter/XmlTm.php +++ b/src/Zend/Translate/Adapter/XmlTm.php @@ -30,7 +30,6 @@ class Zend_Translate_Adapter_XmlTm extends Zend_Translate_Adapter { // Internal variables private $_file = false; - private $_cleared = array(); private $_lang = null; private $_content = null; private $_tag = null; @@ -121,7 +120,7 @@ private function _contentElement($file, $data) private function _findEncoding($filename) { - $file = file_get_contents($filename, null, null, 0, 100); + $file = file_get_contents($filename, false, null, 0, 100); if (strpos($file, 'encoding') !== false) { $encoding = substr($file, strpos($file, 'encoding') + 9); $encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1); diff --git a/tests/Zend/Translate/Adapter/IniTest.php b/tests/Zend/Translate/Adapter/IniTest.php index 0d29ef0..44b3e18 100644 --- a/tests/Zend/Translate/Adapter/IniTest.php +++ b/tests/Zend/Translate/Adapter/IniTest.php @@ -61,11 +61,7 @@ public function testTranslate() $this->assertEquals('Message 1 (en)', $adapter->_('Message_1')); $this->assertEquals('Message_6', $adapter->translate('Message_6')); $this->assertEquals('Küchen Möbel (en)', $adapter->translate('Cooking_furniture')); - if (0 > version_compare(PHP_VERSION, '5.3.0')) { - $this->assertEquals('Cooking furniture (en)', $adapter->translate('Küchen_Möbel'), var_export($adapter->getMessages('en'), 1)); - } else { - $this->markTestSkipped('PHP 5.3 cannot utilize non-ASCII characters for INI option keys'); - } + $this->assertEquals('Cooking furniture (en)', $adapter->translate('Küchen_Möbel'), var_export($adapter->getMessages('en'), 1)); } public function testIsTranslated()