From e77b86aa05446dbdd47a60a183ffe3be5e215cf7 Mon Sep 17 00:00:00 2001 From: Patrik Foldes Date: Fri, 11 Feb 2022 19:18:54 +0300 Subject: [PATCH] Added support for php 8.1 and thecodingmachine/safe v2 (#16) * Added support for php 8.1 and thecodingmachine/safe v2 * Add readonly keyword, fix ci * Go for major version bump --- .github/workflows/ci.yml | 185 +++++++++++++++++++++++++ .github/workflows/coding-standards.yml | 47 ------- .github/workflows/coverage.yml | 51 ------- .github/workflows/mutation-test.yml | 49 ------- .github/workflows/phpstan.yml | 47 ------- .github/workflows/phpunit.yml | 51 ------- .github/workflows/psalm.yml | 47 ------- CHANGELOG.md | 6 +- composer.json | 30 ++-- infection.json | 5 +- phpstan.neon | 8 +- psalm.xml | 11 +- src/ReservedWordsList.php | 7 + src/ReservedWordsLookupError.php | 1 + tests/ReservedWordsListTest.php | 2 + 15 files changed, 230 insertions(+), 317 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/coding-standards.yml delete mode 100644 .github/workflows/coverage.yml delete mode 100644 .github/workflows/mutation-test.yml delete mode 100644 .github/workflows/phpstan.yml delete mode 100644 .github/workflows/phpunit.yml delete mode 100644 .github/workflows/psalm.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..92b2f27 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,185 @@ +name: "CI" +on: + pull_request: + push: + branches: + - "master" +env: + PHP_EXTENSIONS: "dom, mbstring, xml" + PHP_INI_VALUES: "memory_limit=-1, assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On" +jobs: + unit: + name: "Unit tests ${{matrix.php-version}}-${{matrix.operating-system}}-${{matrix.dependencies}}" + runs-on: ${{matrix.operating-system}} + strategy: + matrix: + operating-system: + - "ubuntu-latest" + - "windows-latest" + php-version: + - "7.3" + - "7.4" + - "8.0" + - "8.1" + dependencies: + - "lowest" + - "highest" + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{matrix.php-version}}" + extensions: "${{env.PHP_EXTENSIONS}}" + ini-values: "${{env.PHP_INI_VALUES}}" + tools: "composer:v2" + - name: "Update composer" + run: "composer self-update" + - name: "Install lowest dependencies" + if: ${{ matrix.dependencies == 'lowest' }} + run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest" + - name: "Install highest dependencies" + if: ${{ matrix.dependencies == 'highest' }} + run: "composer update --no-interaction --no-progress --no-suggest" + - name: "Execute tests" + run: "vendor/bin/phpunit --fail-on-warning" + psalm: + name: "Psalm" + runs-on: "ubuntu-latest" + strategy: + matrix: + operating-system: + - "ubuntu-latest" + php-version: + - "8.1" + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{matrix.php-version}}" + extensions: "${{env.PHP_EXTENSIONS}}" + ini-values: "${{env.PHP_INI_VALUES}}" + tools: "composer:v2" + - name: "Update composer" + run: "composer self-update" + - name: "Install highest dependencies" + run: "composer update --no-interaction --no-progress --no-suggest" + - name: "Execute Psalm" + run: "vendor/bin/psalm" + stan: + name: "PhpStan" + runs-on: "ubuntu-latest" + strategy: + matrix: + operating-system: + - "ubuntu-latest" + php-version: + - "8.1" + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{matrix.php-version}}" + extensions: "${{env.PHP_EXTENSIONS}}" + ini-values: "${{env.PHP_INI_VALUES}}" + tools: "composer:v2" + - name: "Update composer" + run: "composer self-update" + - name: "Install highest dependencies" + run: "composer update --no-interaction --no-progress --no-suggest" + - name: "Execute PhpStan" + run: "composer stan" + code-style: + name: "Code style" + runs-on: "ubuntu-latest" + strategy: + matrix: + operating-system: + - "ubuntu-latest" + php-version: + - "8.1" + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{matrix.php-version}}" + extensions: "${{env.PHP_EXTENSIONS}}" + ini-values: "${{env.PHP_INI_VALUES}}" + tools: "composer:v2, cs2pr" + - name: "Update composer" + run: "composer self-update" + - name: "Install highest dependencies" + run: "composer update --no-interaction --no-progress --no-suggest" + - name: "Execute PhpCs" + run: "vendor/bin/phpcs -q --report=checkstyle | cs2pr" + mutation: + name: "Mutation" + runs-on: "ubuntu-latest" + strategy: + matrix: + operating-system: + - "ubuntu-latest" + php-version: + - "8.1" + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "pcov" + php-version: "${{matrix.php-version}}" + extensions: "${{env.PHP_EXTENSIONS}}" + ini-values: "${{env.PHP_INI_VALUES}}" + tools: "composer:v2" + - name: "Update composer" + run: "composer self-update" + - name: "Install highest dependencies" + run: "composer update --no-interaction --no-progress --no-suggest" + - name: "Execute PhpCs" + run: "vendor/bin/infection" + env: + INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }} + STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} + coverage: + name: "Mutation" + runs-on: "ubuntu-latest" + strategy: + matrix: + operating-system: + - "ubuntu-latest" + php-version: + - "8.1" + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "pcov" + php-version: "${{matrix.php-version}}" + extensions: "${{env.PHP_EXTENSIONS}}" + ini-values: "${{env.PHP_INI_VALUES}}" + tools: "composer:v2" + - name: "Update composer" + run: "composer self-update" + - name: "Install highest dependencies" + run: "composer update --no-interaction --no-progress --no-suggest" + - name: "Code coverage" + run: | + vendor/bin/phpunit --testsuite=unit,functional --coverage-clover build/logs/clover.xml + wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar + php php-coveralls.phar --verbose + env: + COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml deleted file mode 100644 index 6b4744a..0000000 --- a/.github/workflows/coding-standards.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: "Check Coding Standards" -on: - pull_request: - push: - branches: - - "master" -jobs: - coding-standards: - name: "Check Coding Standards" - runs-on: ${{ matrix.operating-system }} - strategy: - matrix: - dependencies: - - "locked" - php-version: - - "8.0" - operating-system: - - "ubuntu-latest" - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "pcov" - php-version: "${{ matrix.php-version }}" - ini-values: memory_limit=-1 - tools: composer:v2, cs2pr - - name: "Cache dependencies" - uses: "actions/cache@v2" - with: - path: | - ~/.composer/cache - vendor - key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - - name: "Install lowest dependencies" - if: ${{ matrix.dependencies == 'lowest' }} - run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest" - - name: "Install highest dependencies" - if: ${{ matrix.dependencies == 'highest' }} - run: "composer update --no-interaction --no-progress --no-suggest" - - name: "Install locked dependencies" - if: ${{ matrix.dependencies == 'locked' }} - run: "composer install --no-interaction --no-progress --no-suggest" - - name: "Coding Standard" - run: "vendor/bin/phpcs -q --report=checkstyle | cs2pr" diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index 722b233..0000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: "Code coverage" -on: - pull_request: - push: - branches: - - "master" -jobs: - coverage: - name: "Code coverage" - runs-on: ${{ matrix.operating-system }} - strategy: - matrix: - dependencies: - - "locked" - php-version: - - "8.0" - operating-system: - - "ubuntu-latest" - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "pcov" - php-version: "${{ matrix.php-version }}" - ini-values: memory_limit=-1 - - name: "Cache dependencies" - uses: "actions/cache@v2" - with: - path: | - ~/.composer/cache - vendor - key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - - name: "Install lowest dependencies" - if: ${{ matrix.dependencies == 'lowest' }} - run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest" - - name: "Install highest dependencies" - if: ${{ matrix.dependencies == 'highest' }} - run: "composer update --no-interaction --no-progress --no-suggest" - - name: "Install locked dependencies" - if: ${{ matrix.dependencies == 'locked' }} - run: "composer install --no-interaction --no-progress --no-suggest" - - name: "Code coverage" - run: | - vendor/bin/phpunit --testsuite=unit,functional --coverage-clover build/logs/clover.xml - wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar - php php-coveralls.phar --verbose - env: - COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} diff --git a/.github/workflows/mutation-test.yml b/.github/workflows/mutation-test.yml deleted file mode 100644 index ffe5554..0000000 --- a/.github/workflows/mutation-test.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: "Mutation tests" -on: - pull_request: - push: - branches: - - "master" -jobs: - mutation-tests: - name: "Mutation tests" - runs-on: ${{ matrix.operating-system }} - strategy: - matrix: - dependencies: - - "locked" - php-version: - - "8.0" - operating-system: - - "ubuntu-latest" - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "pcov" - php-version: "${{ matrix.php-version }}" - ini-values: memory_limit=-1 - - name: "Cache dependencies" - uses: "actions/cache@v2" - with: - path: | - ~/.composer/cache - vendor - key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - - name: "Install lowest dependencies" - if: ${{ matrix.dependencies == 'lowest' }} - run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest" - - name: "Install highest dependencies" - if: ${{ matrix.dependencies == 'highest' }} - run: "composer update --no-interaction --no-progress --no-suggest" - - name: "Install locked dependencies" - if: ${{ matrix.dependencies == 'locked' }} - run: "composer install --no-interaction --no-progress --no-suggest" - - name: "Infection" - run: "vendor/bin/infection" - env: - INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }} - STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml deleted file mode 100644 index a832e3f..0000000 --- a/.github/workflows/phpstan.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: "Static Analysis by PHPStan" -on: - pull_request: - push: - branches: - - "master" -jobs: - static-analysis-phpstan: - name: "Static Analysis by PHPStan" - runs-on: ${{ matrix.operating-system }} - strategy: - matrix: - dependencies: - - "locked" - php-version: - - "8.0" - operating-system: - - "ubuntu-latest" - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "pcov" - php-version: "${{ matrix.php-version }}" - ini-values: memory_limit=-1 - tools: composer:v2, cs2pr - - name: "Cache dependencies" - uses: "actions/cache@v2" - with: - path: | - ~/.composer/cache - vendor - key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - - name: "Install lowest dependencies" - if: ${{ matrix.dependencies == 'lowest' }} - run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest" - - name: "Install highest dependencies" - if: ${{ matrix.dependencies == 'highest' }} - run: "composer update --no-interaction --no-progress --no-suggest" - - name: "Install locked dependencies" - if: ${{ matrix.dependencies == 'locked' }} - run: "composer install --no-interaction --no-progress --no-suggest" - - name: "phpstan" - run: "vendor/bin/phpstan analyse --memory-limit=-1" diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml deleted file mode 100644 index 80b7b03..0000000 --- a/.github/workflows/phpunit.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: "PHPUnit tests" -on: - pull_request: - push: - branches: - - "master" -jobs: - phpunit: - name: "PHPUnit tests" - runs-on: ${{ matrix.operating-system }} - strategy: - matrix: - dependencies: - - "lowest" - - "highest" - - "locked" - php-version: - - "7.3" - - "7.4" - - "8.0" - operating-system: - - "ubuntu-latest" - - "windows-latest" - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "pcov" - php-version: "${{ matrix.php-version }}" - ini-values: memory_limit=-1 - - name: "Cache dependencies" - uses: "actions/cache@v2" - with: - path: | - ~/.composer/cache - vendor - key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - - name: "Install lowest dependencies" - if: ${{ matrix.dependencies == 'lowest' }} - run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest" - - name: "Install highest dependencies" - if: ${{ matrix.dependencies == 'highest' }} - run: "composer update --no-interaction --no-progress --no-suggest" - - name: "Install locked dependencies" - if: ${{ matrix.dependencies == 'locked' }} - run: "composer install --no-interaction --no-progress --no-suggest" - - name: "Tests" - run: "vendor/bin/phpunit --fail-on-warning" diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml deleted file mode 100644 index 453f89e..0000000 --- a/.github/workflows/psalm.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: "Static Analysis by Psalm" -on: - pull_request: - push: - branches: - - "master" -jobs: - static-analysis-psalm: - name: "Static Analysis by Psalm" - runs-on: ${{ matrix.operating-system }} - strategy: - matrix: - dependencies: - - "locked" - php-version: - - "8.0" - operating-system: - - "ubuntu-latest" - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "pcov" - php-version: "${{ matrix.php-version }}" - ini-values: memory_limit=-1 - tools: composer:v2, cs2pr - - name: "Cache dependencies" - uses: "actions/cache@v2" - with: - path: | - ~/.composer/cache - vendor - key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - - name: "Install lowest dependencies" - if: ${{ matrix.dependencies == 'lowest' }} - run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest" - - name: "Install highest dependencies" - if: ${{ matrix.dependencies == 'highest' }} - run: "composer update --no-interaction --no-progress --no-suggest" - - name: "Install locked dependencies" - if: ${{ matrix.dependencies == 'locked' }} - run: "composer install --no-interaction --no-progress --no-suggest" - - name: "psalm" - run: "vendor/bin/psalm --output-format=github --shepherd --stats" diff --git a/CHANGELOG.md b/CHANGELOG.md index 48af0af..365a582 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ -### 2.0.0 (26.12.2020) +### 3.0.0 +* Added support for PHP 8.1 +* Added support for thecodingmachine/safe v2 + +### 2.0.0 * Added support for PHP 8.0 * BC Break: Dropped support of PHP 7.2 diff --git a/composer.json b/composer.json index c1592d2..abe1793 100644 --- a/composer.json +++ b/composer.json @@ -16,18 +16,18 @@ ], "require": { "php": "^7.3|^8.0", - "thecodingmachine/safe": "^1.3" + "thecodingmachine/safe": "^1.3|^2" }, "require-dev": { - "doctrine/coding-standard": "^8.2", - "infection/infection": "^0.18.2", - "phpstan/phpstan": "^0.12.64", - "phpstan/phpstan-phpunit": "^0.12.17", - "phpstan/phpstan-strict-rules": "^0.12.7", - "phpunit/phpunit": "^9.5", - "squizlabs/php_codesniffer": "^3.5", - "thecodingmachine/phpstan-safe-rule": "^1.0", - "vimeo/psalm": "^4.3" + "doctrine/coding-standard": "^9.0", + "infection/infection": "^0.18|dev-master#4a1a2fd250bc5f11d24d59803b19b705a2f67296", + "phpstan/phpstan": "^1.4", + "phpstan/phpstan-phpunit": "^1.0", + "phpstan/phpstan-strict-rules": "^1.1", + "phpunit/phpunit": "^9.5.5", + "squizlabs/php_codesniffer": "^3.6", + "thecodingmachine/phpstan-safe-rule": "^1.2", + "vimeo/psalm": "^4.20" }, "autoload": { "psr-4": { @@ -41,14 +41,18 @@ }, "config": { "sort-packages": true, - "preferred-install": "dist" + "preferred-install": "dist", + "allow-plugins": { + "infection/extension-installer": true, + "dealerdirect/phpcodesniffer-composer-installer": true + } }, "scripts": { "cs": "phpcs", "csfix": "phpcbf", "psalm": "psalm", - "stan": "phpstan analyze", - "test": "phpunit", + "stan": "phpstan analyze --memory-limit=-1", + "test": "phpunit --fail-on-warning", "mutation": "infection", "all": "composer psalm && composer stan && composer test && composer mutation && composer cs" } diff --git a/infection.json b/infection.json index bb832b1..f36b68e 100644 --- a/infection.json +++ b/infection.json @@ -6,10 +6,7 @@ }, "timeout": 3, "logs": { - "text": "php://stderr", - "badge": { - "branch": "master" - } + "text": "php://stderr" }, "mutators": { "@default": true, diff --git a/phpstan.neon b/phpstan.neon index 44c2601..760cc2a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,11 +7,15 @@ parameters: treatPhpDocTypesAsCertain: false ignoreErrors: - - message: '#Call to static method PHPUnit\\Framework\\Assert::assertIsString\(\) with string will always evaluate to true\.#' + message: '#Call to static method PHPUnit\\Framework\\Assert::assertIsString\(\) with .* will always evaluate to true\.#' paths: - %currentWorkingDirectory%/tests/ReservedWordsListTest.php - - message: '#Call to static method PHPUnit\\Framework\\Assert::assertIsArray\(\) with array.+will always evaluate to true\.#' + message: '#Call to static method PHPUnit\\Framework\\Assert::assertIsArray\(\) with .+ will always evaluate to true\.#' + paths: + - %currentWorkingDirectory%/tests/ReservedWordsListTest.php + - + message: '#Call to static method PHPUnit\\Framework\\Assert::assertArrayHasKey\(\) with .+ will always evaluate to true\.#' paths: - %currentWorkingDirectory%/tests/ReservedWordsListTest.php includes: diff --git a/psalm.xml b/psalm.xml index f986edd..6230a54 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,12 +1,13 @@ diff --git a/src/ReservedWordsList.php b/src/ReservedWordsList.php index 534440d..7dc9450 100644 --- a/src/ReservedWordsList.php +++ b/src/ReservedWordsList.php @@ -645,5 +645,12 @@ final class ReservedWordsList 'function' => false, 'method' => false, ], + 'readonly' => [ + 'constant' => false, + 'namespace' => false, + 'class' => '8.1', + 'function' => false, + 'method' => false, + ], ]; } diff --git a/src/ReservedWordsLookupError.php b/src/ReservedWordsLookupError.php index e8c2ea8..7215bf5 100644 --- a/src/ReservedWordsLookupError.php +++ b/src/ReservedWordsLookupError.php @@ -12,6 +12,7 @@ final class ReservedWordsLookupError extends RuntimeException { public static function invalidPhpVersion(string $phpVersion, string $correctFormat): self { + /** @psalm-suppress DeprecatedFunction */ return new self( sprintf('Invalid PHP version: %s, the correct format is: %s', $phpVersion, $correctFormat) ); diff --git a/tests/ReservedWordsListTest.php b/tests/ReservedWordsListTest.php index c455465..77a7771 100644 --- a/tests/ReservedWordsListTest.php +++ b/tests/ReservedWordsListTest.php @@ -59,6 +59,8 @@ public function testReservedWordsList(): void /** * @param string|bool|array $constraint + * + * @phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint */ private function isValidConstraint($constraint): bool {