From 4619c66cd3d11cdd496df3657e6da6c47b6f4e89 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 4 Dec 2021 22:26:53 +0000 Subject: [PATCH 01/53] Fixed incorrect branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 08b74ead..05c7ff86 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "1.1-dev" }, "phpstan": { "includes": [ From d992449ad2e736c21ef27ba407bb7b487252d415 Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Thu, 16 Dec 2021 19:33:21 +0100 Subject: [PATCH 02/53] Composer > Remove `--no-suggest` You are using the deprecated option "--no-suggest". It has no effect and will break in Composer 3. --- .github/workflows/build.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 59b79ed7..85d9184d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -37,7 +37,7 @@ jobs: run: "composer validate" - name: "Install dependencies" - run: "composer install --no-interaction --no-progress --no-suggest" + run: "composer install --no-interaction --no-progress" - name: "Downgrade PHPUnit" if: matrix.php-version == '7.1' || matrix.php-version == '7.2' || matrix.php-version == '7.3' @@ -65,7 +65,7 @@ jobs: run: "composer validate" - name: "Install dependencies" - run: "composer install --no-interaction --no-progress --no-suggest" + run: "composer install --no-interaction --no-progress" - name: "Lint" run: "make lint" @@ -103,11 +103,11 @@ jobs: - name: "Install lowest dependencies" if: ${{ matrix.dependencies == 'lowest' }} - run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest" + run: "composer update --prefer-lowest --no-interaction --no-progress" - name: "Install highest dependencies" if: ${{ matrix.dependencies == 'highest' }} - run: "composer update --no-interaction --no-progress --no-suggest" + run: "composer update --no-interaction --no-progress" - name: "Downgrade PHPUnit" if: matrix.php-version == '7.1' || matrix.php-version == '7.2' || matrix.php-version == '7.3' @@ -148,11 +148,11 @@ jobs: - name: "Install lowest dependencies" if: ${{ matrix.dependencies == 'lowest' }} - run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest" + run: "composer update --prefer-lowest --no-interaction --no-progress" - name: "Install highest dependencies" if: ${{ matrix.dependencies == 'highest' }} - run: "composer update --no-interaction --no-progress --no-suggest" + run: "composer update --no-interaction --no-progress" - name: "Downgrade PHPUnit" if: matrix.php-version == '7.1' || matrix.php-version == '7.2' || matrix.php-version == '7.3' From 3468390c72c1d9094c1059350f793378df2d1ed7 Mon Sep 17 00:00:00 2001 From: Martin Herndl Date: Thu, 6 Jan 2022 13:33:28 +0100 Subject: [PATCH 03/53] Allow Composer plugins --- build-cs/composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build-cs/composer.json b/build-cs/composer.json index ed7744e1..cc6a4983 100644 --- a/build-cs/composer.json +++ b/build-cs/composer.json @@ -3,5 +3,10 @@ "consistence-community/coding-standard": "^3.10", "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", "slevomat/coding-standard": "^6.4" + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } From d883e37bf39bda26b5e28c89f2a3e5bd20e7bb5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Mirtes?= Date: Sun, 16 Jan 2022 09:42:17 +0100 Subject: [PATCH 04/53] Tweet release action --- .github/workflows/release-tweet.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/release-tweet.yml diff --git a/.github/workflows/release-tweet.yml b/.github/workflows/release-tweet.yml new file mode 100644 index 00000000..09b39ded --- /dev/null +++ b/.github/workflows/release-tweet.yml @@ -0,0 +1,24 @@ +name: Tweet release + +# More triggers +# https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#release +on: + release: + types: [published] + +jobs: + tweet: + runs-on: ubuntu-latest + steps: + - uses: Eomm/why-don-t-you-tweet@v1 + if: ${{ !github.event.repository.private }} + with: + # GitHub event payload + # https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#release + tweet-message: "New release: ${{ github.event.repository.name }} ${{ github.event.release.tag_name }} ${{ github.event.release.html_url }} #phpstan" + env: + # Get your tokens from https://developer.twitter.com/apps + TWITTER_CONSUMER_API_KEY: ${{ secrets.TWITTER_CONSUMER_API_KEY }} + TWITTER_CONSUMER_API_SECRET: ${{ secrets.TWITTER_CONSUMER_API_SECRET }} + TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} + TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} From 8646e9d53850fe5a0d0365aadf2436642f72a077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Mirtes?= Date: Sun, 16 Jan 2022 11:56:38 +0100 Subject: [PATCH 05/53] Update release.yml --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 225470a6..5ed11761 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,13 +20,13 @@ jobs: id: changelog uses: metcalfc/changelog-generator@v1.0.0 with: - myToken: ${{ secrets.GITHUB_TOKEN }} + myToken: ${{ secrets.PHPSTAN_BOT_TOKEN }} - name: "Create release" id: create-release uses: actions/create-release@v1 env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.PHPSTAN_BOT_TOKEN }} with: tag_name: ${{ github.ref }} release_name: ${{ github.ref }} From 38008d09c253bab873f6328cda067274b21cd53f Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 30 Jan 2022 18:04:39 +0100 Subject: [PATCH 06/53] Update phpunit.xml --- phpunit.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index e5f534e4..f60bcee1 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -10,7 +10,7 @@ beStrictAboutTodoAnnotatedTests="true" failOnRisky="true" failOnWarning="true" - xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" + xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xml" > From 47b03fb9c310c34d13b7986795a8dbaa4b0e3b66 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Tue, 4 Jan 2022 05:53:58 -0500 Subject: [PATCH 07/53] docs(readme): improve "Enabling rules one-by-one" Add note about allowing some rules alternatively by using `ignoreErrors` option when `phpstan/extension-installer` is installed. --- README.md | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d5400c61..304e26a8 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,13 @@ includes: ## Enabling rules one-by-one -If you don't want to start using all the available strict rules at once but only one or two, you can! Just don't include the whole `rules.neon` from this package in your configuration, but look at its contents and copy only the rules you want to your configuration under the `services` key: +If you don't want to start using all the available strict rules at once but only one or two, you can! -``` +### Without extension-installer + +Just don't include the whole `rules.neon` from this package in your configuration, but look at its contents and copy only the rules you want to your configuration under the `services` key: + +```neon services: - class: PHPStan\Rules\StrictCalls\StrictFunctionCallsRule @@ -73,4 +77,15 @@ services: - phpstan.rules.rule ``` -*Unfortunately, you cannot use phpstan/extension-installer in this case.* +### With extension-installer + +Unfortunately, by using `phpstan/extension-installer` you can't enable it one by one, ***but you can [ignore specific errors](https://phpstan.org/user-guide/ignoring-errors) instead***. + +For example: + +```neon +parameters: + ignoreErrors: + - '#Construct empty\(\) is not allowed. Use more strict comparison.#' + - '#Call to function in_array\(\) requires parameter \#3 to be set.#' +``` From b36180ef0ff0f8d9228cdd4e4fcc29bd254742c6 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 1 Feb 2022 21:48:31 +0000 Subject: [PATCH 08/53] chore(deps): add renovate.json --- renovate.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 renovate.json diff --git a/renovate.json b/renovate.json new file mode 100644 index 00000000..f45d8f11 --- /dev/null +++ b/renovate.json @@ -0,0 +1,5 @@ +{ + "extends": [ + "config:base" + ] +} From b451fb4206e56ef7949f91b9c79fcd34864ad229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Mirtes?= Date: Tue, 1 Feb 2022 23:10:41 +0100 Subject: [PATCH 09/53] Update and rename renovate.json to .github/renovate.json --- .github/renovate.json | 23 +++++++++++++++++++++++ renovate.json | 5 ----- 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 .github/renovate.json delete mode 100644 renovate.json diff --git a/.github/renovate.json b/.github/renovate.json new file mode 100644 index 00000000..597ad920 --- /dev/null +++ b/.github/renovate.json @@ -0,0 +1,23 @@ +{ + "extends": [ + "config:base" + ], + "rangeStrategy": "update-lockfile", + "packageRules": [ + { + "matchPaths": ["+(composer.json)"], + "enabled": true, + "groupName": "root-composer" + }, + { + "matchPaths": ["build-cs/**"], + "enabled": true, + "groupName": "build-cs" + }, + { + "matchPaths": [".github/**"], + "enabled": true, + "groupName": "github-actions" + } + ] +} diff --git a/renovate.json b/renovate.json deleted file mode 100644 index f45d8f11..00000000 --- a/renovate.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": [ - "config:base" - ] -} From c6d6ca0463719d7c57c9580159c2f7595d4c3363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Mirtes?= Date: Tue, 1 Feb 2022 23:11:02 +0100 Subject: [PATCH 10/53] Delete dependabot.yml --- .github/dependabot.yml | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 15b77335..00000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,17 +0,0 @@ -version: 2 -updates: - - package-ecosystem: composer - directory: "/" - schedule: - interval: monthly - open-pull-requests-limit: 10 - - package-ecosystem: composer - directory: "/build-cs" - schedule: - interval: monthly - open-pull-requests-limit: 10 - - package-ecosystem: github-actions - directory: "/" - schedule: - interval: monthly - open-pull-requests-limit: 10 From 68781541930cf0b62fefa85c2a9f65c0ea2f6e6a Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 1 Feb 2022 22:11:07 +0000 Subject: [PATCH 11/53] chore(deps): update metcalfc/changelog-generator action to v1.0.1 --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5ed11761..24a1d301 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: - name: Generate changelog id: changelog - uses: metcalfc/changelog-generator@v1.0.0 + uses: metcalfc/changelog-generator@v1.0.1 with: myToken: ${{ secrets.PHPSTAN_BOT_TOKEN }} From 698c15b5e8b463d44a1d72976b169b7239119535 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 2 Feb 2022 00:11:33 +0000 Subject: [PATCH 12/53] chore(deps): update github-actions --- .github/workflows/lock-closed-issues.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lock-closed-issues.yml b/.github/workflows/lock-closed-issues.yml index 960c1ba5..9ea53272 100644 --- a/.github/workflows/lock-closed-issues.yml +++ b/.github/workflows/lock-closed-issues.yml @@ -8,7 +8,7 @@ jobs: lock: runs-on: ubuntu-latest steps: - - uses: dessant/lock-threads@v2 + - uses: dessant/lock-threads@v3 with: github-token: ${{ github.token }} issue-lock-inactive-days: '31' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 24a1d301..0ebed840 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: - name: Generate changelog id: changelog - uses: metcalfc/changelog-generator@v1.0.1 + uses: metcalfc/changelog-generator@v3.0.0 with: myToken: ${{ secrets.PHPSTAN_BOT_TOKEN }} From e7c273e1ed75b83a9024693055d94a1981cae857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Mirtes?= Date: Wed, 2 Feb 2022 15:38:32 +0100 Subject: [PATCH 13/53] Update lock-closed-issues.yml --- .github/workflows/lock-closed-issues.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lock-closed-issues.yml b/.github/workflows/lock-closed-issues.yml index 9ea53272..a05d4173 100644 --- a/.github/workflows/lock-closed-issues.yml +++ b/.github/workflows/lock-closed-issues.yml @@ -11,11 +11,11 @@ jobs: - uses: dessant/lock-threads@v3 with: github-token: ${{ github.token }} - issue-lock-inactive-days: '31' - issue-exclude-created-before: '' - issue-exclude-labels: '' - issue-lock-labels: '' - issue-lock-comment: > + issue-inactive-days: '31' + exclude-issue-created-before: '' + exclude-any-issue-labels: '' + add-issue-labels: '' + issue-comment: > This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. From cb75e7c1c2db932aceb703c77d5c79a492e1484e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Mirtes?= Date: Wed, 2 Feb 2022 16:38:12 +0100 Subject: [PATCH 14/53] Update renovate.json --- .github/renovate.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/renovate.json b/.github/renovate.json index 597ad920..b775cc18 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -1,6 +1,7 @@ { "extends": [ - "config:base" + "config:base", + "schedule:weekly" ], "rangeStrategy": "update-lockfile", "packageRules": [ From 32d667d714e08c695891c3e8ca02b0beb6f769f2 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 1 Feb 2022 22:11:11 +0000 Subject: [PATCH 15/53] chore(deps): update dependency slevomat/coding-standard to v7 --- .gitignore | 2 +- build-cs/.gitignore | 1 - build-cs/composer.json | 2 +- build-cs/composer.lock | 327 ++++++++++++++++++ phpcs.xml | 99 ++++-- .../BooleanInBooleanAndRule.php | 10 +- .../BooleanInBooleanNotRule.php | 14 +- .../BooleanInBooleanOrRule.php | 10 +- .../BooleanInElseIfConditionRule.php | 14 +- .../BooleanInIfConditionRule.php | 14 +- .../BooleanInTernaryOperatorRule.php | 14 +- .../BooleanRuleHelper.php | 4 +- src/Rules/Cast/UselessCastRule.php | 7 +- .../RequireParentConstructCallRule.php | 19 +- .../DisallowedBacktickRule.php | 10 +- .../DisallowedEmptyRule.php | 9 +- .../DisallowedImplicitArrayCreationRule.php | 22 +- .../DisallowedShortTernaryRule.php | 8 +- .../OverwriteVariablesWithForLoopInitRule.php | 5 +- .../OverwriteVariablesWithForeachRule.php | 8 +- src/Rules/Functions/ClosureUsesThisRule.php | 2 + .../WrongCaseOfInheritedMethodRule.php | 11 +- ...ndInArithmeticIncrementOrDecrementRule.php | 12 +- .../OperandInArithmeticPostDecrementRule.php | 4 +- .../OperandInArithmeticPostIncrementRule.php | 4 +- .../OperandInArithmeticPreDecrementRule.php | 4 +- .../OperandInArithmeticPreIncrementRule.php | 4 +- .../OperandsInArithmeticAdditionRule.php | 15 +- .../OperandsInArithmeticDivisionRule.php | 15 +- ...OperandsInArithmeticExponentiationRule.php | 15 +- .../OperandsInArithmeticModuloRule.php | 15 +- ...OperandsInArithmeticMultiplicationRule.php | 15 +- .../OperandsInArithmeticSubtractionRule.php | 15 +- src/Rules/Operators/OperatorRuleHelper.php | 7 +- ...DynamicCallOnStaticMethodsCallableRule.php | 10 +- .../DynamicCallOnStaticMethodsRule.php | 11 +- .../StrictCalls/StrictFunctionCallsRule.php | 24 +- .../MatchingTypeInSwitchCaseConditionRule.php | 18 +- .../VariableMethodCallRule.php | 5 +- .../VariableMethodCallableRule.php | 1 + .../VariablePropertyFetchRule.php | 6 +- .../VariableStaticMethodCallRule.php | 5 +- .../VariableStaticMethodCallableRule.php | 1 + .../VariableStaticPropertyFetchRule.php | 5 +- .../VariableVariablesRule.php | 5 +- tests/Levels/LevelsIntegrationTest.php | 4 +- .../BooleanInBooleanAndRuleTest.php | 5 +- .../BooleanInBooleanNotRuleTest.php | 3 +- .../BooleanInBooleanOrRuleTest.php | 5 +- .../BooleanInElseIfConditionRuleTest.php | 3 +- .../BooleanInIfConditionRuleTest.php | 3 +- .../BooleanInTernaryOperatorRuleTest.php | 3 +- tests/Rules/Cast/UselessCastRuleTest.php | 7 +- .../RequireParentConstructCallRuleTest.php | 6 +- .../DisallowedBacktickRuleTest.php | 3 +- .../DisallowedEmptyRuleTest.php | 3 +- ...isallowedImplicitArrayCreationRuleTest.php | 3 +- .../DisallowedShortTernaryRuleTest.php | 5 +- .../WrongCaseOfInheritedMethodRuleTest.php | 7 +- ...ArithmeticIncrementOrDecrementRuleTest.php | 3 +- .../OperandsInArithmeticAdditionRuleTest.php | 3 +- .../OperandsInArithmeticDivisionRuleTest.php | 3 +- ...andsInArithmeticExponentiationRuleTest.php | 3 +- .../OperandsInArithmeticModuloRuleTest.php | 3 +- ...andsInArithmeticMultiplicationRuleTest.php | 3 +- ...perandsInArithmeticSubtractionRuleTest.php | 3 +- ...micCallOnStaticMethodsCallableRuleTest.php | 6 +- .../DynamicCallOnStaticMethodsRuleTest.php | 3 +- .../StrictFunctionCallsRuleTest.php | 3 +- ...chingTypeInSwitchCaseConditionRuleTest.php | 8 +- .../VariableMethodCallableRuleTest.php | 1 + 71 files changed, 723 insertions(+), 207 deletions(-) create mode 100644 build-cs/composer.lock diff --git a/.gitignore b/.gitignore index d6a83e59..2db21315 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /tests/tmp /vendor -composer.lock +/composer.lock .phpunit.result.cache diff --git a/build-cs/.gitignore b/build-cs/.gitignore index ff72e2d0..61ead866 100644 --- a/build-cs/.gitignore +++ b/build-cs/.gitignore @@ -1,2 +1 @@ -/composer.lock /vendor diff --git a/build-cs/composer.json b/build-cs/composer.json index cc6a4983..e3079710 100644 --- a/build-cs/composer.json +++ b/build-cs/composer.json @@ -2,7 +2,7 @@ "require-dev": { "consistence-community/coding-standard": "^3.10", "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", - "slevomat/coding-standard": "^6.4" + "slevomat/coding-standard": "^7.0" }, "config": { "allow-plugins": { diff --git a/build-cs/composer.lock b/build-cs/composer.lock new file mode 100644 index 00000000..70af78f9 --- /dev/null +++ b/build-cs/composer.lock @@ -0,0 +1,327 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "4485bbedba7bcc71ace5f69dbb9b6c47", + "packages": [], + "packages-dev": [ + { + "name": "consistence-community/coding-standard", + "version": "3.11.1", + "source": { + "type": "git", + "url": "https://github.com/consistence-community/coding-standard.git", + "reference": "4632fead8c9ee8f50044fcbce9f66c797b34c0df" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/consistence-community/coding-standard/zipball/4632fead8c9ee8f50044fcbce9f66c797b34c0df", + "reference": "4632fead8c9ee8f50044fcbce9f66c797b34c0df", + "shasum": "" + }, + "require": { + "php": ">=7.4", + "slevomat/coding-standard": "~7.0", + "squizlabs/php_codesniffer": "~3.6.0" + }, + "replace": { + "consistence/coding-standard": "3.10.*" + }, + "require-dev": { + "phing/phing": "2.16.4", + "php-parallel-lint/php-parallel-lint": "1.3.0", + "phpunit/phpunit": "9.5.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "Consistence\\": [ + "Consistence" + ] + }, + "classmap": [ + "Consistence" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "VaĊĦek Purchart", + "email": "me@vasekpurchart.cz", + "homepage": "http://vasekpurchart.cz" + } + ], + "description": "Consistence - Coding Standard - PHP Code Sniffer rules", + "keywords": [ + "Coding Standard", + "PHPCodeSniffer", + "codesniffer", + "coding", + "cs", + "phpcs", + "ruleset", + "sniffer", + "standard" + ], + "support": { + "issues": "https://github.com/consistence-community/coding-standard/issues", + "source": "https://github.com/consistence-community/coding-standard/tree/3.11.1" + }, + "time": "2021-05-03T18:13:22+00:00" + }, + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v0.7.2", + "source": { + "type": "git", + "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", + "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", + "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + }, + { + "name": "Contributors", + "homepage": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcbf", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues", + "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" + }, + "time": "2022-02-04T12:51:07+00:00" + }, + { + "name": "phpstan/phpdoc-parser", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "dbc093d7af60eff5cd575d2ed761b15ed40bd08e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/dbc093d7af60eff5cd575d2ed761b15ed40bd08e", + "reference": "dbc093d7af60eff5cd575d2ed761b15ed40bd08e", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^1.0", + "phpstan/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^9.5", + "symfony/process": "^5.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPDoc parser with support for nullable, intersection and generic types", + "support": { + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.2.0" + }, + "time": "2021-09-16T20:46:02+00:00" + }, + { + "name": "slevomat/coding-standard", + "version": "7.0.18", + "source": { + "type": "git", + "url": "https://github.com/slevomat/coding-standard.git", + "reference": "b81ac84f41a4797dc25c8ede1b0718e2a74be0fc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/b81ac84f41a4797dc25c8ede1b0718e2a74be0fc", + "reference": "b81ac84f41a4797dc25c8ede1b0718e2a74be0fc", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7", + "php": "^7.1 || ^8.0", + "phpstan/phpdoc-parser": "^1.0.0", + "squizlabs/php_codesniffer": "^3.6.1" + }, + "require-dev": { + "phing/phing": "2.17.0", + "php-parallel-lint/php-parallel-lint": "1.3.1", + "phpstan/phpstan": "1.2.0", + "phpstan/phpstan-deprecation-rules": "1.0.0", + "phpstan/phpstan-phpunit": "1.0.0", + "phpstan/phpstan-strict-rules": "1.1.0", + "phpunit/phpunit": "7.5.20|8.5.21|9.5.10" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-master": "7.x-dev" + } + }, + "autoload": { + "psr-4": { + "SlevomatCodingStandard\\": "SlevomatCodingStandard" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "support": { + "issues": "https://github.com/slevomat/coding-standard/issues", + "source": "https://github.com/slevomat/coding-standard/tree/7.0.18" + }, + "funding": [ + { + "url": "https://github.com/kukulich", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard", + "type": "tidelift" + } + ], + "time": "2021-12-07T17:19:06+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.6.2", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/5e4e71592f69da17871dba6e80dd51bce74a351a", + "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards" + ], + "support": { + "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", + "source": "https://github.com/squizlabs/PHP_CodeSniffer", + "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + }, + "time": "2021-12-12T21:44:58+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.2.0" +} diff --git a/phpcs.xml b/phpcs.xml index 067a6a8e..95032a6e 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,5 +1,6 @@ - + + @@ -8,59 +9,103 @@ src tests + - - + + - + + + + + - + - - - - - - + + + + + 10 - - - + + 10 + - - - + + + + + 10 + + + - - + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - tests/tmp + + tests/*/data diff --git a/src/Rules/BooleansInConditions/BooleanInBooleanAndRule.php b/src/Rules/BooleansInConditions/BooleanInBooleanAndRule.php index 93f7ee63..53140ccf 100644 --- a/src/Rules/BooleansInConditions/BooleanInBooleanAndRule.php +++ b/src/Rules/BooleansInConditions/BooleanInBooleanAndRule.php @@ -2,13 +2,17 @@ namespace PHPStan\Rules\BooleansInConditions; +use PhpParser\Node; +use PHPStan\Analyser\Scope; use PHPStan\Node\BooleanAndNode; +use PHPStan\Rules\Rule; use PHPStan\Type\VerbosityLevel; +use function sprintf; /** - * @implements \PHPStan\Rules\Rule + * @implements Rule */ -class BooleanInBooleanAndRule implements \PHPStan\Rules\Rule +class BooleanInBooleanAndRule implements Rule { /** @var BooleanRuleHelper */ @@ -24,7 +28,7 @@ public function getNodeType(): string return BooleanAndNode::class; } - public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array + public function processNode(Node $node, Scope $scope): array { $originalNode = $node->getOriginalNode(); $messages = []; diff --git a/src/Rules/BooleansInConditions/BooleanInBooleanNotRule.php b/src/Rules/BooleansInConditions/BooleanInBooleanNotRule.php index 7a492e82..0e53c873 100644 --- a/src/Rules/BooleansInConditions/BooleanInBooleanNotRule.php +++ b/src/Rules/BooleansInConditions/BooleanInBooleanNotRule.php @@ -2,9 +2,14 @@ namespace PHPStan\Rules\BooleansInConditions; +use PhpParser\Node; +use PhpParser\Node\Expr\BooleanNot; +use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; use PHPStan\Type\VerbosityLevel; +use function sprintf; -class BooleanInBooleanNotRule implements \PHPStan\Rules\Rule +class BooleanInBooleanNotRule implements Rule { /** @var BooleanRuleHelper */ @@ -17,15 +22,14 @@ public function __construct(BooleanRuleHelper $helper) public function getNodeType(): string { - return \PhpParser\Node\Expr\BooleanNot::class; + return BooleanNot::class; } /** - * @param \PhpParser\Node\Expr\BooleanNot $node - * @param \PHPStan\Analyser\Scope $scope + * @param BooleanNot $node * @return string[] errors */ - public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array + public function processNode(Node $node, Scope $scope): array { if ($this->helper->passesAsBoolean($scope, $node->expr)) { return []; diff --git a/src/Rules/BooleansInConditions/BooleanInBooleanOrRule.php b/src/Rules/BooleansInConditions/BooleanInBooleanOrRule.php index a95738b0..bf98c5cd 100644 --- a/src/Rules/BooleansInConditions/BooleanInBooleanOrRule.php +++ b/src/Rules/BooleansInConditions/BooleanInBooleanOrRule.php @@ -2,13 +2,17 @@ namespace PHPStan\Rules\BooleansInConditions; +use PhpParser\Node; +use PHPStan\Analyser\Scope; use PHPStan\Node\BooleanOrNode; +use PHPStan\Rules\Rule; use PHPStan\Type\VerbosityLevel; +use function sprintf; /** - * @implements \PHPStan\Rules\Rule + * @implements Rule */ -class BooleanInBooleanOrRule implements \PHPStan\Rules\Rule +class BooleanInBooleanOrRule implements Rule { /** @var BooleanRuleHelper */ @@ -24,7 +28,7 @@ public function getNodeType(): string return BooleanOrNode::class; } - public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array + public function processNode(Node $node, Scope $scope): array { $originalNode = $node->getOriginalNode(); $messages = []; diff --git a/src/Rules/BooleansInConditions/BooleanInElseIfConditionRule.php b/src/Rules/BooleansInConditions/BooleanInElseIfConditionRule.php index 0553f31c..8dfe3dac 100644 --- a/src/Rules/BooleansInConditions/BooleanInElseIfConditionRule.php +++ b/src/Rules/BooleansInConditions/BooleanInElseIfConditionRule.php @@ -2,9 +2,14 @@ namespace PHPStan\Rules\BooleansInConditions; +use PhpParser\Node; +use PhpParser\Node\Stmt\ElseIf_; +use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; use PHPStan\Type\VerbosityLevel; +use function sprintf; -class BooleanInElseIfConditionRule implements \PHPStan\Rules\Rule +class BooleanInElseIfConditionRule implements Rule { /** @var BooleanRuleHelper */ @@ -17,15 +22,14 @@ public function __construct(BooleanRuleHelper $helper) public function getNodeType(): string { - return \PhpParser\Node\Stmt\ElseIf_::class; + return ElseIf_::class; } /** - * @param \PhpParser\Node\Stmt\ElseIf_ $node - * @param \PHPStan\Analyser\Scope $scope + * @param ElseIf_ $node * @return string[] errors */ - public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array + public function processNode(Node $node, Scope $scope): array { if ($this->helper->passesAsBoolean($scope, $node->cond)) { return []; diff --git a/src/Rules/BooleansInConditions/BooleanInIfConditionRule.php b/src/Rules/BooleansInConditions/BooleanInIfConditionRule.php index a77cad92..7b1cbfb8 100644 --- a/src/Rules/BooleansInConditions/BooleanInIfConditionRule.php +++ b/src/Rules/BooleansInConditions/BooleanInIfConditionRule.php @@ -2,9 +2,14 @@ namespace PHPStan\Rules\BooleansInConditions; +use PhpParser\Node; +use PhpParser\Node\Stmt\If_; +use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; use PHPStan\Type\VerbosityLevel; +use function sprintf; -class BooleanInIfConditionRule implements \PHPStan\Rules\Rule +class BooleanInIfConditionRule implements Rule { /** @var BooleanRuleHelper */ @@ -17,15 +22,14 @@ public function __construct(BooleanRuleHelper $helper) public function getNodeType(): string { - return \PhpParser\Node\Stmt\If_::class; + return If_::class; } /** - * @param \PhpParser\Node\Stmt\If_ $node - * @param \PHPStan\Analyser\Scope $scope + * @param If_ $node * @return string[] errors */ - public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array + public function processNode(Node $node, Scope $scope): array { if ($this->helper->passesAsBoolean($scope, $node->cond)) { return []; diff --git a/src/Rules/BooleansInConditions/BooleanInTernaryOperatorRule.php b/src/Rules/BooleansInConditions/BooleanInTernaryOperatorRule.php index 08e4f838..5d389b7a 100644 --- a/src/Rules/BooleansInConditions/BooleanInTernaryOperatorRule.php +++ b/src/Rules/BooleansInConditions/BooleanInTernaryOperatorRule.php @@ -2,9 +2,14 @@ namespace PHPStan\Rules\BooleansInConditions; +use PhpParser\Node; +use PhpParser\Node\Expr\Ternary; +use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; use PHPStan\Type\VerbosityLevel; +use function sprintf; -class BooleanInTernaryOperatorRule implements \PHPStan\Rules\Rule +class BooleanInTernaryOperatorRule implements Rule { /** @var BooleanRuleHelper */ @@ -17,15 +22,14 @@ public function __construct(BooleanRuleHelper $helper) public function getNodeType(): string { - return \PhpParser\Node\Expr\Ternary::class; + return Ternary::class; } /** - * @param \PhpParser\Node\Expr\Ternary $node - * @param \PHPStan\Analyser\Scope $scope + * @param Ternary $node * @return string[] errors */ - public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array + public function processNode(Node $node, Scope $scope): array { if ($node->if === null) { return []; // elvis ?: diff --git a/src/Rules/BooleansInConditions/BooleanRuleHelper.php b/src/Rules/BooleansInConditions/BooleanRuleHelper.php index 98457542..9b167588 100644 --- a/src/Rules/BooleansInConditions/BooleanRuleHelper.php +++ b/src/Rules/BooleansInConditions/BooleanRuleHelper.php @@ -13,7 +13,7 @@ class BooleanRuleHelper { - /** @var \PHPStan\Rules\RuleLevelHelper */ + /** @var RuleLevelHelper */ private $ruleLevelHelper; public function __construct(RuleLevelHelper $ruleLevelHelper) @@ -31,7 +31,7 @@ public function passesAsBoolean(Scope $scope, Expr $expr): bool $scope, $expr, '', - function (Type $type): bool { + static function (Type $type): bool { return $type instanceof BooleanType; } ); diff --git a/src/Rules/Cast/UselessCastRule.php b/src/Rules/Cast/UselessCastRule.php index 1766c1c2..70f762f6 100644 --- a/src/Rules/Cast/UselessCastRule.php +++ b/src/Rules/Cast/UselessCastRule.php @@ -5,14 +5,16 @@ use PhpParser\Node; use PhpParser\Node\Expr\Cast; use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; use PHPStan\Rules\RuleError; use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\ErrorType; use PHPStan\Type\GeneralizePrecision; use PHPStan\Type\TypeUtils; use PHPStan\Type\VerbosityLevel; +use function sprintf; -class UselessCastRule implements \PHPStan\Rules\Rule +class UselessCastRule implements Rule { /** @var bool */ @@ -29,8 +31,7 @@ public function getNodeType(): string } /** - * @param \PhpParser\Node\Expr\Cast $node - * @param \PHPStan\Analyser\Scope $scope + * @param Cast $node * @return RuleError[] errors */ public function processNode(Node $node, Scope $scope): array diff --git a/src/Rules/Classes/RequireParentConstructCallRule.php b/src/Rules/Classes/RequireParentConstructCallRule.php index d3420ad4..fd386b2e 100644 --- a/src/Rules/Classes/RequireParentConstructCallRule.php +++ b/src/Rules/Classes/RequireParentConstructCallRule.php @@ -3,11 +3,16 @@ namespace PHPStan\Rules\Classes; use PhpParser\Node; +use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Name; use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; +use PHPStan\ShouldNotHappenException; +use ReflectionClass; +use function sprintf; -class RequireParentConstructCallRule implements \PHPStan\Rules\Rule +class RequireParentConstructCallRule implements Rule { public function getNodeType(): string @@ -16,14 +21,13 @@ public function getNodeType(): string } /** - * @param \PhpParser\Node\Stmt\ClassMethod $node - * @param \PHPStan\Analyser\Scope $scope + * @param ClassMethod $node * @return string[] */ public function processNode(Node $node, Scope $scope): array { if (!$scope->isInClass()) { - throw new \PHPStan\ShouldNotHappenException(); + throw new ShouldNotHappenException(); } if ($scope->isInTrait()) { @@ -85,7 +89,7 @@ private function callsParentConstruct(Node $parserNode): bool } $statement = $this->ignoreErrorSuppression($statement); - if ($statement instanceof \PhpParser\Node\Expr\StaticCall) { + if ($statement instanceof StaticCall) { if ( $statement->class instanceof Name && ((string) $statement->class === 'parent') @@ -105,10 +109,9 @@ private function callsParentConstruct(Node $parserNode): bool } /** - * @param \ReflectionClass $classReflection - * @return \ReflectionClass|false + * @return ReflectionClass|false */ - private function getParentConstructorClass(\ReflectionClass $classReflection) + private function getParentConstructorClass(ReflectionClass $classReflection) { while ($classReflection->getParentClass() !== false) { $constructor = $classReflection->getParentClass()->hasMethod('__construct') ? $classReflection->getParentClass()->getMethod('__construct') : null; diff --git a/src/Rules/DisallowedConstructs/DisallowedBacktickRule.php b/src/Rules/DisallowedConstructs/DisallowedBacktickRule.php index e90dfc9c..aab3824d 100644 --- a/src/Rules/DisallowedConstructs/DisallowedBacktickRule.php +++ b/src/Rules/DisallowedConstructs/DisallowedBacktickRule.php @@ -3,19 +3,21 @@ namespace PHPStan\Rules\DisallowedConstructs; use PhpParser\Node; +use PhpParser\Node\Expr\Empty_; +use PhpParser\Node\Expr\ShellExec; use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; -class DisallowedBacktickRule implements \PHPStan\Rules\Rule +class DisallowedBacktickRule implements Rule { public function getNodeType(): string { - return \PhpParser\Node\Expr\ShellExec::class; + return ShellExec::class; } /** - * @param \PhpParser\Node\Expr\Empty_ $node - * @param \PHPStan\Analyser\Scope $scope + * @param Empty_ $node * @return string[] */ public function processNode(Node $node, Scope $scope): array diff --git a/src/Rules/DisallowedConstructs/DisallowedEmptyRule.php b/src/Rules/DisallowedConstructs/DisallowedEmptyRule.php index 547d5ecb..9a867cd5 100644 --- a/src/Rules/DisallowedConstructs/DisallowedEmptyRule.php +++ b/src/Rules/DisallowedConstructs/DisallowedEmptyRule.php @@ -3,19 +3,20 @@ namespace PHPStan\Rules\DisallowedConstructs; use PhpParser\Node; +use PhpParser\Node\Expr\Empty_; use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; -class DisallowedEmptyRule implements \PHPStan\Rules\Rule +class DisallowedEmptyRule implements Rule { public function getNodeType(): string { - return \PhpParser\Node\Expr\Empty_::class; + return Empty_::class; } /** - * @param \PhpParser\Node\Expr\Empty_ $node - * @param \PHPStan\Analyser\Scope $scope + * @param Empty_ $node * @return string[] */ public function processNode(Node $node, Scope $scope): array diff --git a/src/Rules/DisallowedConstructs/DisallowedImplicitArrayCreationRule.php b/src/Rules/DisallowedConstructs/DisallowedImplicitArrayCreationRule.php index 4aa7c1c4..322d0dac 100644 --- a/src/Rules/DisallowedConstructs/DisallowedImplicitArrayCreationRule.php +++ b/src/Rules/DisallowedConstructs/DisallowedImplicitArrayCreationRule.php @@ -2,33 +2,39 @@ namespace PHPStan\Rules\DisallowedConstructs; +use PhpParser\Node; +use PhpParser\Node\Expr\ArrayDimFetch; +use PhpParser\Node\Expr\Assign; +use PhpParser\Node\Expr\Variable; use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; +use function is_string; +use function sprintf; -class DisallowedImplicitArrayCreationRule implements \PHPStan\Rules\Rule +class DisallowedImplicitArrayCreationRule implements Rule { public function getNodeType(): string { - return \PhpParser\Node\Expr\Assign::class; + return Assign::class; } /** - * @param \PhpParser\Node\Expr\Assign $node - * @param \PHPStan\Analyser\Scope $scope + * @param Assign $node * @return string[] */ - public function processNode(\PhpParser\Node $node, Scope $scope): array + public function processNode(Node $node, Scope $scope): array { - if (!$node->var instanceof \PhpParser\Node\Expr\ArrayDimFetch) { + if (!$node->var instanceof ArrayDimFetch) { return []; } $node = $node->var; - while ($node instanceof \PhpParser\Node\Expr\ArrayDimFetch) { + while ($node instanceof ArrayDimFetch) { $node = $node->var; } - if (!$node instanceof \PhpParser\Node\Expr\Variable) { + if (!$node instanceof Variable) { return []; } diff --git a/src/Rules/DisallowedConstructs/DisallowedShortTernaryRule.php b/src/Rules/DisallowedConstructs/DisallowedShortTernaryRule.php index a42e7cb8..59db24ac 100644 --- a/src/Rules/DisallowedConstructs/DisallowedShortTernaryRule.php +++ b/src/Rules/DisallowedConstructs/DisallowedShortTernaryRule.php @@ -3,17 +3,19 @@ namespace PHPStan\Rules\DisallowedConstructs; use PhpParser\Node; +use PhpParser\Node\Expr\Ternary; use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; /** - * @implements \PHPStan\Rules\Rule<\PhpParser\Node\Expr\Ternary> + * @implements Rule */ -class DisallowedShortTernaryRule implements \PHPStan\Rules\Rule +class DisallowedShortTernaryRule implements Rule { public function getNodeType(): string { - return \PhpParser\Node\Expr\Ternary::class; + return Ternary::class; } public function processNode(Node $node, Scope $scope): array diff --git a/src/Rules/ForLoop/OverwriteVariablesWithForLoopInitRule.php b/src/Rules/ForLoop/OverwriteVariablesWithForLoopInitRule.php index 286cab20..ca8f631c 100644 --- a/src/Rules/ForLoop/OverwriteVariablesWithForLoopInitRule.php +++ b/src/Rules/ForLoop/OverwriteVariablesWithForLoopInitRule.php @@ -8,6 +8,8 @@ use PhpParser\Node\Stmt\For_; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use function is_string; +use function sprintf; /** * @implements Rule @@ -22,7 +24,6 @@ public function getNodeType(): string /** * @param For_ $node - * @param Scope $scope * @return string[] */ public function processNode(Node $node, Scope $scope): array @@ -42,8 +43,6 @@ public function processNode(Node $node, Scope $scope): array } /** - * @param Scope $scope - * @param Expr $expr * @return string[] */ private function checkValueVar(Scope $scope, Expr $expr): array diff --git a/src/Rules/ForeachLoop/OverwriteVariablesWithForeachRule.php b/src/Rules/ForeachLoop/OverwriteVariablesWithForeachRule.php index 2bb5ccb6..dbf16d25 100644 --- a/src/Rules/ForeachLoop/OverwriteVariablesWithForeachRule.php +++ b/src/Rules/ForeachLoop/OverwriteVariablesWithForeachRule.php @@ -4,8 +4,11 @@ use PhpParser\Node; use PhpParser\Node\Expr; +use PhpParser\Node\Stmt\Foreach_; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use function is_string; +use function sprintf; class OverwriteVariablesWithForeachRule implements Rule { @@ -16,8 +19,7 @@ public function getNodeType(): string } /** - * @param \PhpParser\Node\Stmt\Foreach_ $node - * @param \PHPStan\Analyser\Scope $scope + * @param Foreach_ $node * @return string[] */ public function processNode(Node $node, Scope $scope): array @@ -39,8 +41,6 @@ public function processNode(Node $node, Scope $scope): array } /** - * @param Scope $scope - * @param Expr $expr * @return string[] */ private function checkValueVar(Scope $scope, Expr $expr): array diff --git a/src/Rules/Functions/ClosureUsesThisRule.php b/src/Rules/Functions/ClosureUsesThisRule.php index 60018f45..eab861db 100644 --- a/src/Rules/Functions/ClosureUsesThisRule.php +++ b/src/Rules/Functions/ClosureUsesThisRule.php @@ -7,6 +7,8 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\ThisType; +use function is_string; +use function sprintf; /** * @implements Rule diff --git a/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php b/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php index 76310a78..09388a2d 100644 --- a/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php +++ b/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php @@ -2,12 +2,16 @@ namespace PHPStan\Rules\Methods; +use PhpParser\Node; +use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Analyser\Scope; use PHPStan\Node\InClassMethodNode; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\MethodReflection; +use PHPStan\Rules\Rule; +use function sprintf; -class WrongCaseOfInheritedMethodRule implements \PHPStan\Rules\Rule +class WrongCaseOfInheritedMethodRule implements Rule { public function getNodeType(): string @@ -16,12 +20,11 @@ public function getNodeType(): string } /** - * @param \PhpParser\Node\Stmt\ClassMethod $node - * @param \PHPStan\Analyser\Scope $scope + * @param ClassMethod $node * @return string[] */ public function processNode( - \PhpParser\Node $node, + Node $node, Scope $scope ): array { diff --git a/src/Rules/Operators/OperandInArithmeticIncrementOrDecrementRule.php b/src/Rules/Operators/OperandInArithmeticIncrementOrDecrementRule.php index 2822d19c..c11b6eaa 100644 --- a/src/Rules/Operators/OperandInArithmeticIncrementOrDecrementRule.php +++ b/src/Rules/Operators/OperandInArithmeticIncrementOrDecrementRule.php @@ -2,8 +2,15 @@ namespace PHPStan\Rules\Operators; +use PhpParser\Node; +use PhpParser\Node\Expr\PostDec; +use PhpParser\Node\Expr\PostInc; +use PhpParser\Node\Expr\PreDec; +use PhpParser\Node\Expr\PreInc; +use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; use PHPStan\Type\VerbosityLevel; +use function sprintf; abstract class OperandInArithmeticIncrementOrDecrementRule implements Rule { @@ -17,11 +24,10 @@ public function __construct(OperatorRuleHelper $helper) } /** - * @param \PhpParser\Node\Expr\PreInc|\PhpParser\Node\Expr\PreDec|\PhpParser\Node\Expr\PostInc|\PhpParser\Node\Expr\PostDec $node - * @param \PHPStan\Analyser\Scope $scope + * @param PreInc|PreDec|PostInc|PostDec $node * @return string[] errors */ - public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array + public function processNode(Node $node, Scope $scope): array { $messages = []; $varType = $scope->getType($node->var); diff --git a/src/Rules/Operators/OperandInArithmeticPostDecrementRule.php b/src/Rules/Operators/OperandInArithmeticPostDecrementRule.php index 1bdaf989..d96763a0 100644 --- a/src/Rules/Operators/OperandInArithmeticPostDecrementRule.php +++ b/src/Rules/Operators/OperandInArithmeticPostDecrementRule.php @@ -2,12 +2,14 @@ namespace PHPStan\Rules\Operators; +use PhpParser\Node\Expr\PostDec; + class OperandInArithmeticPostDecrementRule extends OperandInArithmeticIncrementOrDecrementRule { public function getNodeType(): string { - return \PhpParser\Node\Expr\PostDec::class; + return PostDec::class; } protected function describeOperation(): string diff --git a/src/Rules/Operators/OperandInArithmeticPostIncrementRule.php b/src/Rules/Operators/OperandInArithmeticPostIncrementRule.php index d1fe3f30..a4e15eec 100644 --- a/src/Rules/Operators/OperandInArithmeticPostIncrementRule.php +++ b/src/Rules/Operators/OperandInArithmeticPostIncrementRule.php @@ -2,12 +2,14 @@ namespace PHPStan\Rules\Operators; +use PhpParser\Node\Expr\PostInc; + class OperandInArithmeticPostIncrementRule extends OperandInArithmeticIncrementOrDecrementRule { public function getNodeType(): string { - return \PhpParser\Node\Expr\PostInc::class; + return PostInc::class; } protected function describeOperation(): string diff --git a/src/Rules/Operators/OperandInArithmeticPreDecrementRule.php b/src/Rules/Operators/OperandInArithmeticPreDecrementRule.php index 74f67efb..e5da2efa 100644 --- a/src/Rules/Operators/OperandInArithmeticPreDecrementRule.php +++ b/src/Rules/Operators/OperandInArithmeticPreDecrementRule.php @@ -2,12 +2,14 @@ namespace PHPStan\Rules\Operators; +use PhpParser\Node\Expr\PreDec; + class OperandInArithmeticPreDecrementRule extends OperandInArithmeticIncrementOrDecrementRule { public function getNodeType(): string { - return \PhpParser\Node\Expr\PreDec::class; + return PreDec::class; } protected function describeOperation(): string diff --git a/src/Rules/Operators/OperandInArithmeticPreIncrementRule.php b/src/Rules/Operators/OperandInArithmeticPreIncrementRule.php index dbb2cfa1..32fb2474 100644 --- a/src/Rules/Operators/OperandInArithmeticPreIncrementRule.php +++ b/src/Rules/Operators/OperandInArithmeticPreIncrementRule.php @@ -2,12 +2,14 @@ namespace PHPStan\Rules\Operators; +use PhpParser\Node\Expr\PreInc; + class OperandInArithmeticPreIncrementRule extends OperandInArithmeticIncrementOrDecrementRule { public function getNodeType(): string { - return \PhpParser\Node\Expr\PreInc::class; + return PreInc::class; } protected function describeOperation(): string diff --git a/src/Rules/Operators/OperandsInArithmeticAdditionRule.php b/src/Rules/Operators/OperandsInArithmeticAdditionRule.php index e5ae9977..c0e5ca32 100644 --- a/src/Rules/Operators/OperandsInArithmeticAdditionRule.php +++ b/src/Rules/Operators/OperandsInArithmeticAdditionRule.php @@ -2,11 +2,17 @@ namespace PHPStan\Rules\Operators; +use PhpParser\Node; +use PhpParser\Node\Expr\BinaryOp\BooleanAnd; +use PhpParser\Node\Expr\BinaryOp\Plus; +use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; use PHPStan\Type\ArrayType; use PHPStan\Type\MixedType; use PHPStan\Type\VerbosityLevel; +use function sprintf; -class OperandsInArithmeticAdditionRule implements \PHPStan\Rules\Rule +class OperandsInArithmeticAdditionRule implements Rule { /** @var OperatorRuleHelper */ @@ -19,15 +25,14 @@ public function __construct(OperatorRuleHelper $helper) public function getNodeType(): string { - return \PhpParser\Node\Expr\BinaryOp\Plus::class; + return Plus::class; } /** - * @param \PhpParser\Node\Expr\BinaryOp\BooleanAnd $node - * @param \PHPStan\Analyser\Scope $scope + * @param BooleanAnd $node * @return string[] errors */ - public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array + public function processNode(Node $node, Scope $scope): array { $leftType = $scope->getType($node->left); $rightType = $scope->getType($node->right); diff --git a/src/Rules/Operators/OperandsInArithmeticDivisionRule.php b/src/Rules/Operators/OperandsInArithmeticDivisionRule.php index 7c1a9fa7..43656eaa 100644 --- a/src/Rules/Operators/OperandsInArithmeticDivisionRule.php +++ b/src/Rules/Operators/OperandsInArithmeticDivisionRule.php @@ -2,9 +2,15 @@ namespace PHPStan\Rules\Operators; +use PhpParser\Node; +use PhpParser\Node\Expr\BinaryOp\BooleanAnd; +use PhpParser\Node\Expr\BinaryOp\Div; +use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; use PHPStan\Type\VerbosityLevel; +use function sprintf; -class OperandsInArithmeticDivisionRule implements \PHPStan\Rules\Rule +class OperandsInArithmeticDivisionRule implements Rule { /** @var OperatorRuleHelper */ @@ -17,15 +23,14 @@ public function __construct(OperatorRuleHelper $helper) public function getNodeType(): string { - return \PhpParser\Node\Expr\BinaryOp\Div::class; + return Div::class; } /** - * @param \PhpParser\Node\Expr\BinaryOp\BooleanAnd $node - * @param \PHPStan\Analyser\Scope $scope + * @param BooleanAnd $node * @return string[] errors */ - public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array + public function processNode(Node $node, Scope $scope): array { $messages = []; $leftType = $scope->getType($node->left); diff --git a/src/Rules/Operators/OperandsInArithmeticExponentiationRule.php b/src/Rules/Operators/OperandsInArithmeticExponentiationRule.php index 65ea2b41..59e55f14 100644 --- a/src/Rules/Operators/OperandsInArithmeticExponentiationRule.php +++ b/src/Rules/Operators/OperandsInArithmeticExponentiationRule.php @@ -2,9 +2,15 @@ namespace PHPStan\Rules\Operators; +use PhpParser\Node; +use PhpParser\Node\Expr\BinaryOp\BooleanAnd; +use PhpParser\Node\Expr\BinaryOp\Pow; +use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; use PHPStan\Type\VerbosityLevel; +use function sprintf; -class OperandsInArithmeticExponentiationRule implements \PHPStan\Rules\Rule +class OperandsInArithmeticExponentiationRule implements Rule { /** @var OperatorRuleHelper */ @@ -17,15 +23,14 @@ public function __construct(OperatorRuleHelper $helper) public function getNodeType(): string { - return \PhpParser\Node\Expr\BinaryOp\Pow::class; + return Pow::class; } /** - * @param \PhpParser\Node\Expr\BinaryOp\BooleanAnd $node - * @param \PHPStan\Analyser\Scope $scope + * @param BooleanAnd $node * @return string[] errors */ - public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array + public function processNode(Node $node, Scope $scope): array { $messages = []; $leftType = $scope->getType($node->left); diff --git a/src/Rules/Operators/OperandsInArithmeticModuloRule.php b/src/Rules/Operators/OperandsInArithmeticModuloRule.php index 8f17353c..b89c8515 100644 --- a/src/Rules/Operators/OperandsInArithmeticModuloRule.php +++ b/src/Rules/Operators/OperandsInArithmeticModuloRule.php @@ -2,9 +2,15 @@ namespace PHPStan\Rules\Operators; +use PhpParser\Node; +use PhpParser\Node\Expr\BinaryOp\BooleanAnd; +use PhpParser\Node\Expr\BinaryOp\Mod; +use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; use PHPStan\Type\VerbosityLevel; +use function sprintf; -class OperandsInArithmeticModuloRule implements \PHPStan\Rules\Rule +class OperandsInArithmeticModuloRule implements Rule { /** @var OperatorRuleHelper */ @@ -17,15 +23,14 @@ public function __construct(OperatorRuleHelper $helper) public function getNodeType(): string { - return \PhpParser\Node\Expr\BinaryOp\Mod::class; + return Mod::class; } /** - * @param \PhpParser\Node\Expr\BinaryOp\BooleanAnd $node - * @param \PHPStan\Analyser\Scope $scope + * @param BooleanAnd $node * @return string[] errors */ - public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array + public function processNode(Node $node, Scope $scope): array { $messages = []; $leftType = $scope->getType($node->left); diff --git a/src/Rules/Operators/OperandsInArithmeticMultiplicationRule.php b/src/Rules/Operators/OperandsInArithmeticMultiplicationRule.php index 46b0120b..c1e16ae8 100644 --- a/src/Rules/Operators/OperandsInArithmeticMultiplicationRule.php +++ b/src/Rules/Operators/OperandsInArithmeticMultiplicationRule.php @@ -2,9 +2,15 @@ namespace PHPStan\Rules\Operators; +use PhpParser\Node; +use PhpParser\Node\Expr\BinaryOp\BooleanAnd; +use PhpParser\Node\Expr\BinaryOp\Mul; +use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; use PHPStan\Type\VerbosityLevel; +use function sprintf; -class OperandsInArithmeticMultiplicationRule implements \PHPStan\Rules\Rule +class OperandsInArithmeticMultiplicationRule implements Rule { /** @var OperatorRuleHelper */ @@ -17,15 +23,14 @@ public function __construct(OperatorRuleHelper $helper) public function getNodeType(): string { - return \PhpParser\Node\Expr\BinaryOp\Mul::class; + return Mul::class; } /** - * @param \PhpParser\Node\Expr\BinaryOp\BooleanAnd $node - * @param \PHPStan\Analyser\Scope $scope + * @param BooleanAnd $node * @return string[] errors */ - public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array + public function processNode(Node $node, Scope $scope): array { $messages = []; $leftType = $scope->getType($node->left); diff --git a/src/Rules/Operators/OperandsInArithmeticSubtractionRule.php b/src/Rules/Operators/OperandsInArithmeticSubtractionRule.php index 093876db..d5907ae5 100644 --- a/src/Rules/Operators/OperandsInArithmeticSubtractionRule.php +++ b/src/Rules/Operators/OperandsInArithmeticSubtractionRule.php @@ -2,9 +2,15 @@ namespace PHPStan\Rules\Operators; +use PhpParser\Node; +use PhpParser\Node\Expr\BinaryOp\BooleanAnd; +use PhpParser\Node\Expr\BinaryOp\Minus; +use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; use PHPStan\Type\VerbosityLevel; +use function sprintf; -class OperandsInArithmeticSubtractionRule implements \PHPStan\Rules\Rule +class OperandsInArithmeticSubtractionRule implements Rule { /** @var OperatorRuleHelper */ @@ -17,15 +23,14 @@ public function __construct(OperatorRuleHelper $helper) public function getNodeType(): string { - return \PhpParser\Node\Expr\BinaryOp\Minus::class; + return Minus::class; } /** - * @param \PhpParser\Node\Expr\BinaryOp\BooleanAnd $node - * @param \PHPStan\Analyser\Scope $scope + * @param BooleanAnd $node * @return string[] errors */ - public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array + public function processNode(Node $node, Scope $scope): array { $messages = []; $leftType = $scope->getType($node->left); diff --git a/src/Rules/Operators/OperatorRuleHelper.php b/src/Rules/Operators/OperatorRuleHelper.php index be071571..ca7b2349 100644 --- a/src/Rules/Operators/OperatorRuleHelper.php +++ b/src/Rules/Operators/OperatorRuleHelper.php @@ -6,6 +6,7 @@ use PHPStan\Analyser\Scope; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Type\Accessory\AccessoryNumericStringType; +use PHPStan\Type\BenevolentUnionType; use PHPStan\Type\ErrorType; use PHPStan\Type\FloatType; use PHPStan\Type\IntegerType; @@ -18,7 +19,7 @@ class OperatorRuleHelper { - /** @var \PHPStan\Rules\RuleLevelHelper */ + /** @var RuleLevelHelper */ private $ruleLevelHelper; public function __construct(RuleLevelHelper $ruleLevelHelper) @@ -59,7 +60,7 @@ private function isSubtypeOfNumber(Scope $scope, Expr $expr): bool $scope, $expr, '', - function (Type $type) use ($acceptedType): bool { + static function (Type $type) use ($acceptedType): bool { return $acceptedType->isSuperTypeOf($type)->yes(); } )->getType(); @@ -69,7 +70,7 @@ function (Type $type) use ($acceptedType): bool { } $isSuperType = $acceptedType->isSuperTypeOf($type); - if ($type instanceof \PHPStan\Type\BenevolentUnionType) { + if ($type instanceof BenevolentUnionType) { return !$isSuperType->no(); } diff --git a/src/Rules/StrictCalls/DynamicCallOnStaticMethodsCallableRule.php b/src/Rules/StrictCalls/DynamicCallOnStaticMethodsCallableRule.php index 6aefe622..95e27fec 100644 --- a/src/Rules/StrictCalls/DynamicCallOnStaticMethodsCallableRule.php +++ b/src/Rules/StrictCalls/DynamicCallOnStaticMethodsCallableRule.php @@ -5,17 +5,19 @@ use PhpParser\Node; use PHPStan\Analyser\Scope; use PHPStan\Node\MethodCallableNode; +use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Type\ErrorType; use PHPStan\Type\Type; +use function sprintf; /** - * @implements \PHPStan\Rules\Rule + * @implements Rule */ -class DynamicCallOnStaticMethodsCallableRule implements \PHPStan\Rules\Rule +class DynamicCallOnStaticMethodsCallableRule implements Rule { - /** @var \PHPStan\Rules\RuleLevelHelper */ + /** @var RuleLevelHelper */ private $ruleLevelHelper; public function __construct(RuleLevelHelper $ruleLevelHelper) @@ -39,7 +41,7 @@ public function processNode(Node $node, Scope $scope): array $scope, $node->getVar(), '', - function (Type $type) use ($name): bool { + static function (Type $type) use ($name): bool { return $type->canCallMethods()->yes() && $type->hasMethod($name)->yes(); } )->getType(); diff --git a/src/Rules/StrictCalls/DynamicCallOnStaticMethodsRule.php b/src/Rules/StrictCalls/DynamicCallOnStaticMethodsRule.php index 1ae402a1..c412cb2b 100644 --- a/src/Rules/StrictCalls/DynamicCallOnStaticMethodsRule.php +++ b/src/Rules/StrictCalls/DynamicCallOnStaticMethodsRule.php @@ -5,14 +5,16 @@ use PhpParser\Node; use PhpParser\Node\Expr\MethodCall; use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Type\ErrorType; use PHPStan\Type\Type; +use function sprintf; -class DynamicCallOnStaticMethodsRule implements \PHPStan\Rules\Rule +class DynamicCallOnStaticMethodsRule implements Rule { - /** @var \PHPStan\Rules\RuleLevelHelper */ + /** @var RuleLevelHelper */ private $ruleLevelHelper; public function __construct(RuleLevelHelper $ruleLevelHelper) @@ -26,8 +28,7 @@ public function getNodeType(): string } /** - * @param \PhpParser\Node\Expr\MethodCall $node - * @param \PHPStan\Analyser\Scope $scope + * @param MethodCall $node * @return string[] */ public function processNode(Node $node, Scope $scope): array @@ -41,7 +42,7 @@ public function processNode(Node $node, Scope $scope): array $scope, $node->var, '', - function (Type $type) use ($name): bool { + static function (Type $type) use ($name): bool { return $type->canCallMethods()->yes() && $type->hasMethod($name)->yes(); } )->getType(); diff --git a/src/Rules/StrictCalls/StrictFunctionCallsRule.php b/src/Rules/StrictCalls/StrictFunctionCallsRule.php index 1aeb900d..9a50e548 100644 --- a/src/Rules/StrictCalls/StrictFunctionCallsRule.php +++ b/src/Rules/StrictCalls/StrictFunctionCallsRule.php @@ -2,9 +2,18 @@ namespace PHPStan\Rules\StrictCalls; +use PhpParser\Node; +use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Name; +use PHPStan\Analyser\Scope; +use PHPStan\Broker\Broker; +use PHPStan\Rules\Rule; use PHPStan\Type\Constant\ConstantBooleanType; +use function array_key_exists; +use function sprintf; +use function strtolower; -class StrictFunctionCallsRule implements \PHPStan\Rules\Rule +class StrictFunctionCallsRule implements Rule { /** @var int[] */ @@ -15,27 +24,26 @@ class StrictFunctionCallsRule implements \PHPStan\Rules\Rule 'array_keys' => 2, ]; - /** @var \PHPStan\Broker\Broker */ + /** @var Broker */ private $broker; - public function __construct(\PHPStan\Broker\Broker $broker) + public function __construct(Broker $broker) { $this->broker = $broker; } public function getNodeType(): string { - return \PhpParser\Node\Expr\FuncCall::class; + return FuncCall::class; } /** - * @param \PhpParser\Node\Expr\FuncCall $node - * @param \PHPStan\Analyser\Scope $scope + * @param FuncCall $node * @return string[] errors */ - public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array + public function processNode(Node $node, Scope $scope): array { - if (!$node->name instanceof \PhpParser\Node\Name) { + if (!$node->name instanceof Name) { return []; } diff --git a/src/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRule.php b/src/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRule.php index cdd61e82..bb4bebbf 100644 --- a/src/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRule.php +++ b/src/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRule.php @@ -2,29 +2,35 @@ namespace PHPStan\Rules\SwitchConditions; +use PhpParser\Node; +use PhpParser\Node\Stmt\Switch_; +use PhpParser\PrettyPrinter\Standard; +use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\VerbosityLevel; +use function sprintf; /** - * @implements \PHPStan\Rules\Rule<\PhpParser\Node\Stmt\Switch_> + * @implements Rule */ -class MatchingTypeInSwitchCaseConditionRule implements \PHPStan\Rules\Rule +class MatchingTypeInSwitchCaseConditionRule implements Rule { - /** @var \PhpParser\PrettyPrinter\Standard */ + /** @var Standard */ private $printer; - public function __construct(\PhpParser\PrettyPrinter\Standard $printer) + public function __construct(Standard $printer) { $this->printer = $printer; } public function getNodeType(): string { - return \PhpParser\Node\Stmt\Switch_::class; + return Switch_::class; } - public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array + public function processNode(Node $node, Scope $scope): array { $messages = []; $conditionType = $scope->getType($node->cond); diff --git a/src/Rules/VariableVariables/VariableMethodCallRule.php b/src/Rules/VariableVariables/VariableMethodCallRule.php index 8733f15f..4221cfa8 100644 --- a/src/Rules/VariableVariables/VariableMethodCallRule.php +++ b/src/Rules/VariableVariables/VariableMethodCallRule.php @@ -3,9 +3,11 @@ namespace PHPStan\Rules\VariableVariables; use PhpParser\Node; +use PhpParser\Node\Expr\MethodCall; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; use PHPStan\Type\VerbosityLevel; +use function sprintf; class VariableMethodCallRule implements Rule { @@ -16,8 +18,7 @@ public function getNodeType(): string } /** - * @param \PhpParser\Node\Expr\MethodCall $node - * @param \PHPStan\Analyser\Scope $scope + * @param MethodCall $node * @return string[] */ public function processNode(Node $node, Scope $scope): array diff --git a/src/Rules/VariableVariables/VariableMethodCallableRule.php b/src/Rules/VariableVariables/VariableMethodCallableRule.php index 12e03563..f293b562 100644 --- a/src/Rules/VariableVariables/VariableMethodCallableRule.php +++ b/src/Rules/VariableVariables/VariableMethodCallableRule.php @@ -7,6 +7,7 @@ use PHPStan\Node\MethodCallableNode; use PHPStan\Rules\Rule; use PHPStan\Type\VerbosityLevel; +use function sprintf; /** * @implements Rule diff --git a/src/Rules/VariableVariables/VariablePropertyFetchRule.php b/src/Rules/VariableVariables/VariablePropertyFetchRule.php index d872c6a5..3195c16f 100644 --- a/src/Rules/VariableVariables/VariablePropertyFetchRule.php +++ b/src/Rules/VariableVariables/VariablePropertyFetchRule.php @@ -3,12 +3,14 @@ namespace PHPStan\Rules\VariableVariables; use PhpParser\Node; +use PhpParser\Node\Expr\PropertyFetch; use PHPStan\Analyser\Scope; use PHPStan\Broker\Broker; use PHPStan\Reflection\ClassReflection; use PHPStan\Rules\Rule; use PHPStan\Type\TypeUtils; use PHPStan\Type\VerbosityLevel; +use function sprintf; class VariablePropertyFetchRule implements Rule { @@ -20,7 +22,6 @@ class VariablePropertyFetchRule implements Rule private $universalObjectCratesClasses; /** - * @param Broker $broker * @param string[] $universalObjectCratesClasses */ public function __construct(Broker $broker, array $universalObjectCratesClasses) @@ -35,8 +36,7 @@ public function getNodeType(): string } /** - * @param \PhpParser\Node\Expr\PropertyFetch $node - * @param \PHPStan\Analyser\Scope $scope + * @param PropertyFetch $node * @return string[] */ public function processNode(Node $node, Scope $scope): array diff --git a/src/Rules/VariableVariables/VariableStaticMethodCallRule.php b/src/Rules/VariableVariables/VariableStaticMethodCallRule.php index 5887a4df..0d6b8202 100644 --- a/src/Rules/VariableVariables/VariableStaticMethodCallRule.php +++ b/src/Rules/VariableVariables/VariableStaticMethodCallRule.php @@ -3,9 +3,11 @@ namespace PHPStan\Rules\VariableVariables; use PhpParser\Node; +use PhpParser\Node\Expr\StaticCall; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; use PHPStan\Type\VerbosityLevel; +use function sprintf; class VariableStaticMethodCallRule implements Rule { @@ -16,8 +18,7 @@ public function getNodeType(): string } /** - * @param \PhpParser\Node\Expr\StaticCall $node - * @param \PHPStan\Analyser\Scope $scope + * @param StaticCall $node * @return string[] */ public function processNode(Node $node, Scope $scope): array diff --git a/src/Rules/VariableVariables/VariableStaticMethodCallableRule.php b/src/Rules/VariableVariables/VariableStaticMethodCallableRule.php index 5ea5afe4..8ede1f00 100644 --- a/src/Rules/VariableVariables/VariableStaticMethodCallableRule.php +++ b/src/Rules/VariableVariables/VariableStaticMethodCallableRule.php @@ -7,6 +7,7 @@ use PHPStan\Node\StaticMethodCallableNode; use PHPStan\Rules\Rule; use PHPStan\Type\VerbosityLevel; +use function sprintf; /** * @implements Rule diff --git a/src/Rules/VariableVariables/VariableStaticPropertyFetchRule.php b/src/Rules/VariableVariables/VariableStaticPropertyFetchRule.php index 7e457f93..4b410a7f 100644 --- a/src/Rules/VariableVariables/VariableStaticPropertyFetchRule.php +++ b/src/Rules/VariableVariables/VariableStaticPropertyFetchRule.php @@ -3,9 +3,11 @@ namespace PHPStan\Rules\VariableVariables; use PhpParser\Node; +use PhpParser\Node\Expr\StaticPropertyFetch; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; use PHPStan\Type\VerbosityLevel; +use function sprintf; class VariableStaticPropertyFetchRule implements Rule { @@ -16,8 +18,7 @@ public function getNodeType(): string } /** - * @param \PhpParser\Node\Expr\StaticPropertyFetch $node - * @param \PHPStan\Analyser\Scope $scope + * @param StaticPropertyFetch $node * @return string[] */ public function processNode(Node $node, Scope $scope): array diff --git a/src/Rules/VariableVariables/VariableVariablesRule.php b/src/Rules/VariableVariables/VariableVariablesRule.php index b250742b..9768f21b 100644 --- a/src/Rules/VariableVariables/VariableVariablesRule.php +++ b/src/Rules/VariableVariables/VariableVariablesRule.php @@ -3,8 +3,10 @@ namespace PHPStan\Rules\VariableVariables; use PhpParser\Node; +use PhpParser\Node\Expr\Variable; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use function is_string; class VariableVariablesRule implements Rule { @@ -15,8 +17,7 @@ public function getNodeType(): string } /** - * @param \PhpParser\Node\Expr\Variable $node - * @param \PHPStan\Analyser\Scope $scope + * @param Variable $node * @return string[] */ public function processNode(Node $node, Scope $scope): array diff --git a/tests/Levels/LevelsIntegrationTest.php b/tests/Levels/LevelsIntegrationTest.php index e492ae8d..d1e57d7e 100644 --- a/tests/Levels/LevelsIntegrationTest.php +++ b/tests/Levels/LevelsIntegrationTest.php @@ -2,7 +2,9 @@ namespace PHPStan\Levels; -class LevelsIntegrationTest extends \PHPStan\Testing\LevelsTestCase +use PHPStan\Testing\LevelsTestCase; + +class LevelsIntegrationTest extends LevelsTestCase { /** diff --git a/tests/Rules/BooleansInConditions/BooleanInBooleanAndRuleTest.php b/tests/Rules/BooleansInConditions/BooleanInBooleanAndRuleTest.php index 0c7a6f58..c9244204 100644 --- a/tests/Rules/BooleansInConditions/BooleanInBooleanAndRuleTest.php +++ b/tests/Rules/BooleansInConditions/BooleanInBooleanAndRuleTest.php @@ -4,11 +4,12 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; +use PHPStan\Testing\RuleTestCase; /** - * @extends \PHPStan\Testing\RuleTestCase + * @extends RuleTestCase */ -class BooleanInBooleanAndRuleTest extends \PHPStan\Testing\RuleTestCase +class BooleanInBooleanAndRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/BooleansInConditions/BooleanInBooleanNotRuleTest.php b/tests/Rules/BooleansInConditions/BooleanInBooleanNotRuleTest.php index eb887e7f..33dd205c 100644 --- a/tests/Rules/BooleansInConditions/BooleanInBooleanNotRuleTest.php +++ b/tests/Rules/BooleansInConditions/BooleanInBooleanNotRuleTest.php @@ -4,8 +4,9 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; +use PHPStan\Testing\RuleTestCase; -class BooleanInBooleanNotRuleTest extends \PHPStan\Testing\RuleTestCase +class BooleanInBooleanNotRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/BooleansInConditions/BooleanInBooleanOrRuleTest.php b/tests/Rules/BooleansInConditions/BooleanInBooleanOrRuleTest.php index bfecfd1f..1a4fafb0 100644 --- a/tests/Rules/BooleansInConditions/BooleanInBooleanOrRuleTest.php +++ b/tests/Rules/BooleansInConditions/BooleanInBooleanOrRuleTest.php @@ -4,11 +4,12 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; +use PHPStan\Testing\RuleTestCase; /** - * @extends \PHPStan\Testing\RuleTestCase + * @extends RuleTestCase */ -class BooleanInBooleanOrRuleTest extends \PHPStan\Testing\RuleTestCase +class BooleanInBooleanOrRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/BooleansInConditions/BooleanInElseIfConditionRuleTest.php b/tests/Rules/BooleansInConditions/BooleanInElseIfConditionRuleTest.php index 880ca900..b2df79fc 100644 --- a/tests/Rules/BooleansInConditions/BooleanInElseIfConditionRuleTest.php +++ b/tests/Rules/BooleansInConditions/BooleanInElseIfConditionRuleTest.php @@ -4,8 +4,9 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; +use PHPStan\Testing\RuleTestCase; -class BooleanInElseIfConditionRuleTest extends \PHPStan\Testing\RuleTestCase +class BooleanInElseIfConditionRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/BooleansInConditions/BooleanInIfConditionRuleTest.php b/tests/Rules/BooleansInConditions/BooleanInIfConditionRuleTest.php index 1922a0d5..196af111 100644 --- a/tests/Rules/BooleansInConditions/BooleanInIfConditionRuleTest.php +++ b/tests/Rules/BooleansInConditions/BooleanInIfConditionRuleTest.php @@ -4,8 +4,9 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; +use PHPStan\Testing\RuleTestCase; -class BooleanInIfConditionRuleTest extends \PHPStan\Testing\RuleTestCase +class BooleanInIfConditionRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/BooleansInConditions/BooleanInTernaryOperatorRuleTest.php b/tests/Rules/BooleansInConditions/BooleanInTernaryOperatorRuleTest.php index 17c3fdd7..76bd4ad0 100644 --- a/tests/Rules/BooleansInConditions/BooleanInTernaryOperatorRuleTest.php +++ b/tests/Rules/BooleansInConditions/BooleanInTernaryOperatorRuleTest.php @@ -4,8 +4,9 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; +use PHPStan\Testing\RuleTestCase; -class BooleanInTernaryOperatorRuleTest extends \PHPStan\Testing\RuleTestCase +class BooleanInTernaryOperatorRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/Cast/UselessCastRuleTest.php b/tests/Rules/Cast/UselessCastRuleTest.php index 9d8bcf0a..92bf98cb 100644 --- a/tests/Rules/Cast/UselessCastRuleTest.php +++ b/tests/Rules/Cast/UselessCastRuleTest.php @@ -2,13 +2,16 @@ namespace PHPStan\Rules\Cast; -class UselessCastRuleTest extends \PHPStan\Testing\RuleTestCase +use PHPStan\Rules\Rule; +use PHPStan\Testing\RuleTestCase; + +class UselessCastRuleTest extends RuleTestCase { /** @var bool */ private $treatPhpDocTypesAsCertain; - protected function getRule(): \PHPStan\Rules\Rule + protected function getRule(): Rule { return new UselessCastRule($this->treatPhpDocTypesAsCertain); } diff --git a/tests/Rules/Classes/RequireParentConstructCallRuleTest.php b/tests/Rules/Classes/RequireParentConstructCallRuleTest.php index a390d998..caeee5c8 100644 --- a/tests/Rules/Classes/RequireParentConstructCallRuleTest.php +++ b/tests/Rules/Classes/RequireParentConstructCallRuleTest.php @@ -2,12 +2,14 @@ namespace PHPStan\Rules\Classes; +use PHPStan\Rules\Rule; +use PHPStan\Testing\RuleTestCase; use const PHP_VERSION_ID; -class RequireParentConstructCallRuleTest extends \PHPStan\Testing\RuleTestCase +class RequireParentConstructCallRuleTest extends RuleTestCase { - protected function getRule(): \PHPStan\Rules\Rule + protected function getRule(): Rule { return new RequireParentConstructCallRule(); } diff --git a/tests/Rules/DisallowedConstructs/DisallowedBacktickRuleTest.php b/tests/Rules/DisallowedConstructs/DisallowedBacktickRuleTest.php index 996f2c6e..1b697e0a 100644 --- a/tests/Rules/DisallowedConstructs/DisallowedBacktickRuleTest.php +++ b/tests/Rules/DisallowedConstructs/DisallowedBacktickRuleTest.php @@ -3,8 +3,9 @@ namespace PHPStan\Rules\DisallowedConstructs; use PHPStan\Rules\Rule; +use PHPStan\Testing\RuleTestCase; -class DisallowedBacktickRuleTest extends \PHPStan\Testing\RuleTestCase +class DisallowedBacktickRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/DisallowedConstructs/DisallowedEmptyRuleTest.php b/tests/Rules/DisallowedConstructs/DisallowedEmptyRuleTest.php index 5b9e8188..5ffc7f67 100644 --- a/tests/Rules/DisallowedConstructs/DisallowedEmptyRuleTest.php +++ b/tests/Rules/DisallowedConstructs/DisallowedEmptyRuleTest.php @@ -3,8 +3,9 @@ namespace PHPStan\Rules\DisallowedConstructs; use PHPStan\Rules\Rule; +use PHPStan\Testing\RuleTestCase; -class DisallowedEmptyRuleTest extends \PHPStan\Testing\RuleTestCase +class DisallowedEmptyRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/DisallowedConstructs/DisallowedImplicitArrayCreationRuleTest.php b/tests/Rules/DisallowedConstructs/DisallowedImplicitArrayCreationRuleTest.php index 7b446a82..6092a5f4 100644 --- a/tests/Rules/DisallowedConstructs/DisallowedImplicitArrayCreationRuleTest.php +++ b/tests/Rules/DisallowedConstructs/DisallowedImplicitArrayCreationRuleTest.php @@ -3,8 +3,9 @@ namespace PHPStan\Rules\DisallowedConstructs; use PHPStan\Rules\Rule; +use PHPStan\Testing\RuleTestCase; -class DisallowedImplicitArrayCreationRuleTest extends \PHPStan\Testing\RuleTestCase +class DisallowedImplicitArrayCreationRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/DisallowedConstructs/DisallowedShortTernaryRuleTest.php b/tests/Rules/DisallowedConstructs/DisallowedShortTernaryRuleTest.php index 8d143c3b..3f3b944a 100644 --- a/tests/Rules/DisallowedConstructs/DisallowedShortTernaryRuleTest.php +++ b/tests/Rules/DisallowedConstructs/DisallowedShortTernaryRuleTest.php @@ -3,11 +3,12 @@ namespace PHPStan\Rules\DisallowedConstructs; use PHPStan\Rules\Rule; +use PHPStan\Testing\RuleTestCase; /** - * @extends \PHPStan\Testing\RuleTestCase + * @extends RuleTestCase */ -class DisallowedShortTernaryRuleTest extends \PHPStan\Testing\RuleTestCase +class DisallowedShortTernaryRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/Methods/WrongCaseOfInheritedMethodRuleTest.php b/tests/Rules/Methods/WrongCaseOfInheritedMethodRuleTest.php index c120af9b..b2425faf 100644 --- a/tests/Rules/Methods/WrongCaseOfInheritedMethodRuleTest.php +++ b/tests/Rules/Methods/WrongCaseOfInheritedMethodRuleTest.php @@ -2,10 +2,13 @@ namespace PHPStan\Rules\Methods; -class WrongCaseOfInheritedMethodRuleTest extends \PHPStan\Testing\RuleTestCase +use PHPStan\Rules\Rule; +use PHPStan\Testing\RuleTestCase; + +class WrongCaseOfInheritedMethodRuleTest extends RuleTestCase { - protected function getRule(): \PHPStan\Rules\Rule + protected function getRule(): Rule { return new WrongCaseOfInheritedMethodRule(); } diff --git a/tests/Rules/Operators/OperandInArithmeticIncrementOrDecrementRuleTest.php b/tests/Rules/Operators/OperandInArithmeticIncrementOrDecrementRuleTest.php index 4d041683..490ff939 100644 --- a/tests/Rules/Operators/OperandInArithmeticIncrementOrDecrementRuleTest.php +++ b/tests/Rules/Operators/OperandInArithmeticIncrementOrDecrementRuleTest.php @@ -4,8 +4,9 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; +use PHPStan\Testing\RuleTestCase; -abstract class OperandInArithmeticIncrementOrDecrementRuleTest extends \PHPStan\Testing\RuleTestCase +abstract class OperandInArithmeticIncrementOrDecrementRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/Operators/OperandsInArithmeticAdditionRuleTest.php b/tests/Rules/Operators/OperandsInArithmeticAdditionRuleTest.php index f163e537..95b92b39 100644 --- a/tests/Rules/Operators/OperandsInArithmeticAdditionRuleTest.php +++ b/tests/Rules/Operators/OperandsInArithmeticAdditionRuleTest.php @@ -4,9 +4,10 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; +use PHPStan\Testing\RuleTestCase; use const PHP_VERSION_ID; -class OperandsInArithmeticAdditionRuleTest extends \PHPStan\Testing\RuleTestCase +class OperandsInArithmeticAdditionRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/Operators/OperandsInArithmeticDivisionRuleTest.php b/tests/Rules/Operators/OperandsInArithmeticDivisionRuleTest.php index ece89c07..4e2d3055 100644 --- a/tests/Rules/Operators/OperandsInArithmeticDivisionRuleTest.php +++ b/tests/Rules/Operators/OperandsInArithmeticDivisionRuleTest.php @@ -4,8 +4,9 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; +use PHPStan\Testing\RuleTestCase; -class OperandsInArithmeticDivisionRuleTest extends \PHPStan\Testing\RuleTestCase +class OperandsInArithmeticDivisionRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/Operators/OperandsInArithmeticExponentiationRuleTest.php b/tests/Rules/Operators/OperandsInArithmeticExponentiationRuleTest.php index dc7395c7..53b8d1b8 100644 --- a/tests/Rules/Operators/OperandsInArithmeticExponentiationRuleTest.php +++ b/tests/Rules/Operators/OperandsInArithmeticExponentiationRuleTest.php @@ -4,8 +4,9 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; +use PHPStan\Testing\RuleTestCase; -class OperandsInArithmeticExponentiationRuleTest extends \PHPStan\Testing\RuleTestCase +class OperandsInArithmeticExponentiationRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/Operators/OperandsInArithmeticModuloRuleTest.php b/tests/Rules/Operators/OperandsInArithmeticModuloRuleTest.php index cbf12e7e..f8490466 100644 --- a/tests/Rules/Operators/OperandsInArithmeticModuloRuleTest.php +++ b/tests/Rules/Operators/OperandsInArithmeticModuloRuleTest.php @@ -4,8 +4,9 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; +use PHPStan\Testing\RuleTestCase; -class OperandsInArithmeticModuloRuleTest extends \PHPStan\Testing\RuleTestCase +class OperandsInArithmeticModuloRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/Operators/OperandsInArithmeticMultiplicationRuleTest.php b/tests/Rules/Operators/OperandsInArithmeticMultiplicationRuleTest.php index 5d7ac620..c4b6f25b 100644 --- a/tests/Rules/Operators/OperandsInArithmeticMultiplicationRuleTest.php +++ b/tests/Rules/Operators/OperandsInArithmeticMultiplicationRuleTest.php @@ -4,8 +4,9 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; +use PHPStan\Testing\RuleTestCase; -class OperandsInArithmeticMultiplicationRuleTest extends \PHPStan\Testing\RuleTestCase +class OperandsInArithmeticMultiplicationRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/Operators/OperandsInArithmeticSubtractionRuleTest.php b/tests/Rules/Operators/OperandsInArithmeticSubtractionRuleTest.php index f62e0a28..f7643fd5 100644 --- a/tests/Rules/Operators/OperandsInArithmeticSubtractionRuleTest.php +++ b/tests/Rules/Operators/OperandsInArithmeticSubtractionRuleTest.php @@ -4,8 +4,9 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; +use PHPStan\Testing\RuleTestCase; -class OperandsInArithmeticSubtractionRuleTest extends \PHPStan\Testing\RuleTestCase +class OperandsInArithmeticSubtractionRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/StrictCalls/DynamicCallOnStaticMethodsCallableRuleTest.php b/tests/Rules/StrictCalls/DynamicCallOnStaticMethodsCallableRuleTest.php index e570adcf..53be1727 100644 --- a/tests/Rules/StrictCalls/DynamicCallOnStaticMethodsCallableRuleTest.php +++ b/tests/Rules/StrictCalls/DynamicCallOnStaticMethodsCallableRuleTest.php @@ -4,11 +4,13 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; +use PHPStan\Testing\RuleTestCase; +use const PHP_VERSION_ID; /** - * @extends \PHPStan\Testing\RuleTestCase + * @extends RuleTestCase */ -class DynamicCallOnStaticMethodsCallableRuleTest extends \PHPStan\Testing\RuleTestCase +class DynamicCallOnStaticMethodsCallableRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/StrictCalls/DynamicCallOnStaticMethodsRuleTest.php b/tests/Rules/StrictCalls/DynamicCallOnStaticMethodsRuleTest.php index f9b0a93b..a35919a2 100644 --- a/tests/Rules/StrictCalls/DynamicCallOnStaticMethodsRuleTest.php +++ b/tests/Rules/StrictCalls/DynamicCallOnStaticMethodsRuleTest.php @@ -4,8 +4,9 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; +use PHPStan\Testing\RuleTestCase; -class DynamicCallOnStaticMethodsRuleTest extends \PHPStan\Testing\RuleTestCase +class DynamicCallOnStaticMethodsRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/StrictCalls/StrictFunctionCallsRuleTest.php b/tests/Rules/StrictCalls/StrictFunctionCallsRuleTest.php index 1a7d0f35..b1d34ba8 100644 --- a/tests/Rules/StrictCalls/StrictFunctionCallsRuleTest.php +++ b/tests/Rules/StrictCalls/StrictFunctionCallsRuleTest.php @@ -3,8 +3,9 @@ namespace PHPStan\Rules\StrictCalls; use PHPStan\Rules\Rule; +use PHPStan\Testing\RuleTestCase; -class StrictFunctionCallsRuleTest extends \PHPStan\Testing\RuleTestCase +class StrictFunctionCallsRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRuleTest.php b/tests/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRuleTest.php index 40b61d0e..553cba5e 100644 --- a/tests/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRuleTest.php +++ b/tests/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRuleTest.php @@ -2,17 +2,19 @@ namespace PHPStan\Rules\SwitchConditions; +use PhpParser\PrettyPrinter\Standard; use PHPStan\Rules\Rule; +use PHPStan\Testing\RuleTestCase; /** - * @extends \PHPStan\Testing\RuleTestCase + * @extends RuleTestCase */ -class MatchingTypeInSwitchCaseConditionRuleTest extends \PHPStan\Testing\RuleTestCase +class MatchingTypeInSwitchCaseConditionRuleTest extends RuleTestCase { protected function getRule(): Rule { - return new MatchingTypeInSwitchCaseConditionRule(new \PhpParser\PrettyPrinter\Standard()); + return new MatchingTypeInSwitchCaseConditionRule(new Standard()); } public function testRule(): void diff --git a/tests/Rules/VariableVariables/VariableMethodCallableRuleTest.php b/tests/Rules/VariableVariables/VariableMethodCallableRuleTest.php index b1654ce3..8fc1e418 100644 --- a/tests/Rules/VariableVariables/VariableMethodCallableRuleTest.php +++ b/tests/Rules/VariableVariables/VariableMethodCallableRuleTest.php @@ -4,6 +4,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use const PHP_VERSION_ID; /** * @extends RuleTestCase From 21f7c1b3db0710317be30eefdca7aeedf180ea3e Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 23 Feb 2022 10:40:49 +0100 Subject: [PATCH 16/53] fix build after phpstan-src change --- .../OperandInArithmeticIncrementOrDecrementRuleTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Rules/Operators/OperandInArithmeticIncrementOrDecrementRuleTest.php b/tests/Rules/Operators/OperandInArithmeticIncrementOrDecrementRuleTest.php index 490ff939..02e38f43 100644 --- a/tests/Rules/Operators/OperandInArithmeticIncrementOrDecrementRuleTest.php +++ b/tests/Rules/Operators/OperandInArithmeticIncrementOrDecrementRuleTest.php @@ -26,7 +26,7 @@ public function testRule(): void abstract protected function createRule(OperatorRuleHelper $helper): Rule; /** - * @return mixed[][] + * @return list */ abstract protected function getExpectedErrors(): array; From 53a88676516033fdae8148ca609fcd4d8d20b5a3 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 7 Mar 2022 00:58:22 +0000 Subject: [PATCH 17/53] chore(deps): update actions/checkout action to v3 --- .github/workflows/build.yml | 8 ++++---- .github/workflows/release.yml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 85d9184d..49be33fa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,7 +25,7 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: actions/checkout@v3 - name: "Install PHP" uses: "shivammathur/setup-php@v2" @@ -53,7 +53,7 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: actions/checkout@v3 - name: "Install PHP" uses: "shivammathur/setup-php@v2" @@ -93,7 +93,7 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: actions/checkout@v3 - name: "Install PHP" uses: "shivammathur/setup-php@v2" @@ -136,7 +136,7 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: actions/checkout@v3 - name: "Install PHP" uses: "shivammathur/setup-php@v2" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0ebed840..5fed0458 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,7 +14,7 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: actions/checkout@v3 - name: Generate changelog id: changelog From 6f79156331260ee565828aad6b05abc6528f2a9f Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 7 Mar 2022 00:58:19 +0000 Subject: [PATCH 18/53] chore(deps): update dependency slevomat/coding-standard to v7.0.19 --- build-cs/composer.lock | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/build-cs/composer.lock b/build-cs/composer.lock index 70af78f9..96177edd 100644 --- a/build-cs/composer.lock +++ b/build-cs/composer.lock @@ -200,32 +200,32 @@ }, { "name": "slevomat/coding-standard", - "version": "7.0.18", + "version": "7.0.19", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "b81ac84f41a4797dc25c8ede1b0718e2a74be0fc" + "reference": "bef66a43815bbf9b5f49775e9ded3f7c6ba0cc37" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/b81ac84f41a4797dc25c8ede1b0718e2a74be0fc", - "reference": "b81ac84f41a4797dc25c8ede1b0718e2a74be0fc", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/bef66a43815bbf9b5f49775e9ded3f7c6ba0cc37", + "reference": "bef66a43815bbf9b5f49775e9ded3f7c6ba0cc37", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7", "php": "^7.1 || ^8.0", "phpstan/phpdoc-parser": "^1.0.0", - "squizlabs/php_codesniffer": "^3.6.1" + "squizlabs/php_codesniffer": "^3.6.2" }, "require-dev": { - "phing/phing": "2.17.0", - "php-parallel-lint/php-parallel-lint": "1.3.1", - "phpstan/phpstan": "1.2.0", + "phing/phing": "2.17.2", + "php-parallel-lint/php-parallel-lint": "1.3.2", + "phpstan/phpstan": "1.4.6", "phpstan/phpstan-deprecation-rules": "1.0.0", "phpstan/phpstan-phpunit": "1.0.0", "phpstan/phpstan-strict-rules": "1.1.0", - "phpunit/phpunit": "7.5.20|8.5.21|9.5.10" + "phpunit/phpunit": "7.5.20|8.5.21|9.5.16" }, "type": "phpcodesniffer-standard", "extra": { @@ -245,7 +245,7 @@ "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", "support": { "issues": "https://github.com/slevomat/coding-standard/issues", - "source": "https://github.com/slevomat/coding-standard/tree/7.0.18" + "source": "https://github.com/slevomat/coding-standard/tree/7.0.19" }, "funding": [ { @@ -257,7 +257,7 @@ "type": "tidelift" } ], - "time": "2021-12-07T17:19:06+00:00" + "time": "2022-03-01T18:01:41+00:00" }, { "name": "squizlabs/php_codesniffer", From a2ec629fe8d8ec5941d3c939003a6c6a1bf72af0 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 28 Mar 2022 00:44:25 +0000 Subject: [PATCH 19/53] chore(deps): update dependency slevomat/coding-standard to v7.0.20 --- build-cs/composer.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/build-cs/composer.lock b/build-cs/composer.lock index 96177edd..16f621d4 100644 --- a/build-cs/composer.lock +++ b/build-cs/composer.lock @@ -200,16 +200,16 @@ }, { "name": "slevomat/coding-standard", - "version": "7.0.19", + "version": "7.0.20", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "bef66a43815bbf9b5f49775e9ded3f7c6ba0cc37" + "reference": "cbfadfe34c2c29473bf1e891306b3950b3b4350b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/bef66a43815bbf9b5f49775e9ded3f7c6ba0cc37", - "reference": "bef66a43815bbf9b5f49775e9ded3f7c6ba0cc37", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/cbfadfe34c2c29473bf1e891306b3950b3b4350b", + "reference": "cbfadfe34c2c29473bf1e891306b3950b3b4350b", "shasum": "" }, "require": { @@ -221,11 +221,11 @@ "require-dev": { "phing/phing": "2.17.2", "php-parallel-lint/php-parallel-lint": "1.3.2", - "phpstan/phpstan": "1.4.6", + "phpstan/phpstan": "1.4.10|1.5.0", "phpstan/phpstan-deprecation-rules": "1.0.0", "phpstan/phpstan-phpunit": "1.0.0", "phpstan/phpstan-strict-rules": "1.1.0", - "phpunit/phpunit": "7.5.20|8.5.21|9.5.16" + "phpunit/phpunit": "7.5.20|8.5.21|9.5.19" }, "type": "phpcodesniffer-standard", "extra": { @@ -245,7 +245,7 @@ "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", "support": { "issues": "https://github.com/slevomat/coding-standard/issues", - "source": "https://github.com/slevomat/coding-standard/tree/7.0.19" + "source": "https://github.com/slevomat/coding-standard/tree/7.0.20" }, "funding": [ { @@ -257,7 +257,7 @@ "type": "tidelift" } ], - "time": "2022-03-01T18:01:41+00:00" + "time": "2022-03-25T09:43:20+00:00" }, { "name": "squizlabs/php_codesniffer", From 7c68f14e121abca2274f6ccda34e651ee0c56181 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Mon, 28 Mar 2022 11:30:33 +0200 Subject: [PATCH 20/53] Update workflow --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 49be33fa..19cc6ca2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ on: pull_request: push: branches: - - "master" + - "1.2.x" jobs: lint: From fda0781b58d598ea18c1454a31f89dfe273f4990 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Mon, 28 Mar 2022 11:30:58 +0200 Subject: [PATCH 21/53] Drop support for PHP 7.1, require PHPStan 1.5.0 --- .github/workflows/build.yml | 9 +++------ composer.json | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 19cc6ca2..38309f6a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,6 @@ jobs: strategy: matrix: php-version: - - "7.1" - "7.2" - "7.3" - "7.4" @@ -40,7 +39,7 @@ jobs: run: "composer install --no-interaction --no-progress" - name: "Downgrade PHPUnit" - if: matrix.php-version == '7.1' || matrix.php-version == '7.2' || matrix.php-version == '7.3' + if: matrix.php-version == '7.2' || matrix.php-version == '7.3' run: "composer require --dev phpunit/phpunit:^7.5.20 --update-with-dependencies" - name: "Lint" @@ -81,7 +80,6 @@ jobs: fail-fast: false matrix: php-version: - - "7.1" - "7.2" - "7.3" - "7.4" @@ -110,7 +108,7 @@ jobs: run: "composer update --no-interaction --no-progress" - name: "Downgrade PHPUnit" - if: matrix.php-version == '7.1' || matrix.php-version == '7.2' || matrix.php-version == '7.3' + if: matrix.php-version == '7.2' || matrix.php-version == '7.3' run: "composer require --dev phpunit/phpunit:^7.5.20 --update-with-dependencies" - name: "Tests" @@ -124,7 +122,6 @@ jobs: fail-fast: false matrix: php-version: - - "7.1" - "7.2" - "7.3" - "7.4" @@ -155,7 +152,7 @@ jobs: run: "composer update --no-interaction --no-progress" - name: "Downgrade PHPUnit" - if: matrix.php-version == '7.1' || matrix.php-version == '7.2' || matrix.php-version == '7.3' + if: matrix.php-version == '7.2' || matrix.php-version == '7.3' run: "composer require --dev phpunit/phpunit:^7.5.20 --update-with-dependencies" - name: "PHPStan" diff --git a/composer.json b/composer.json index 05c7ff86..d163e871 100644 --- a/composer.json +++ b/composer.json @@ -6,8 +6,8 @@ "MIT" ], "require": { - "php": "^7.1 || ^8.0", - "phpstan/phpstan": "^1.2.0" + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.5.0" }, "require-dev": { "nikic/php-parser": "^4.13.0", From 313a97a01541a2412891a135cc8bb198e6910d1d Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Mon, 28 Mar 2022 11:31:28 +0200 Subject: [PATCH 22/53] Drop alias --- composer.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/composer.json b/composer.json index d163e871..7970b167 100644 --- a/composer.json +++ b/composer.json @@ -22,9 +22,6 @@ "sort-packages": true }, "extra": { - "branch-alias": { - "dev-master": "1.1-dev" - }, "phpstan": { "includes": [ "rules.neon" From 48af1b4e3a126c4282c5485f15e0b7f04a9c6af2 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 4 Apr 2022 00:08:06 +0000 Subject: [PATCH 23/53] chore(deps): update dependency slevomat/coding-standard to v7.1 --- build-cs/composer.lock | 43 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/build-cs/composer.lock b/build-cs/composer.lock index 16f621d4..5a10fffd 100644 --- a/build-cs/composer.lock +++ b/build-cs/composer.lock @@ -151,35 +151,30 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.2.0", + "version": "1.4.2", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "dbc093d7af60eff5cd575d2ed761b15ed40bd08e" + "reference": "4cb3021a4e10ffe3d5f94a4c34cf4b3f6de2fa3d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/dbc093d7af60eff5cd575d2ed761b15ed40bd08e", - "reference": "dbc093d7af60eff5cd575d2ed761b15ed40bd08e", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/4cb3021a4e10ffe3d5f94a4c34cf4b3f6de2fa3d", + "reference": "4cb3021a4e10ffe3d5f94a4c34cf4b3f6de2fa3d", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0" + "php": "^7.2 || ^8.0" }, "require-dev": { "php-parallel-lint/php-parallel-lint": "^1.2", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^1.0", + "phpstan/phpstan": "^1.5", "phpstan/phpstan-strict-rules": "^1.0", "phpunit/phpunit": "^9.5", "symfony/process": "^5.2" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, "autoload": { "psr-4": { "PHPStan\\PhpDocParser\\": [ @@ -194,36 +189,36 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.2.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.4.2" }, - "time": "2021-09-16T20:46:02+00:00" + "time": "2022-03-30T13:33:37+00:00" }, { "name": "slevomat/coding-standard", - "version": "7.0.20", + "version": "7.1", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "cbfadfe34c2c29473bf1e891306b3950b3b4350b" + "reference": "b521bd358b5f7a7d69e9637fd139e036d8adeb6f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/cbfadfe34c2c29473bf1e891306b3950b3b4350b", - "reference": "cbfadfe34c2c29473bf1e891306b3950b3b4350b", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/b521bd358b5f7a7d69e9637fd139e036d8adeb6f", + "reference": "b521bd358b5f7a7d69e9637fd139e036d8adeb6f", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7", - "php": "^7.1 || ^8.0", - "phpstan/phpdoc-parser": "^1.0.0", + "php": "^7.2 || ^8.0", + "phpstan/phpdoc-parser": "^1.4.1", "squizlabs/php_codesniffer": "^3.6.2" }, "require-dev": { "phing/phing": "2.17.2", "php-parallel-lint/php-parallel-lint": "1.3.2", - "phpstan/phpstan": "1.4.10|1.5.0", + "phpstan/phpstan": "1.4.10|1.5.2", "phpstan/phpstan-deprecation-rules": "1.0.0", - "phpstan/phpstan-phpunit": "1.0.0", + "phpstan/phpstan-phpunit": "1.0.0|1.1.0", "phpstan/phpstan-strict-rules": "1.1.0", "phpunit/phpunit": "7.5.20|8.5.21|9.5.19" }, @@ -245,7 +240,7 @@ "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", "support": { "issues": "https://github.com/slevomat/coding-standard/issues", - "source": "https://github.com/slevomat/coding-standard/tree/7.0.20" + "source": "https://github.com/slevomat/coding-standard/tree/7.1" }, "funding": [ { @@ -257,7 +252,7 @@ "type": "tidelift" } ], - "time": "2022-03-25T09:43:20+00:00" + "time": "2022-03-29T12:44:16+00:00" }, { "name": "squizlabs/php_codesniffer", @@ -323,5 +318,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" } From 5fd59352257a55df844475a3ffc62e26c613a6a7 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 21 Apr 2022 15:03:20 +0200 Subject: [PATCH 24/53] Require PHPStan 1.6.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7970b167..f9c8f0c3 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ ], "require": { "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.5.0" + "phpstan/phpstan": "^1.6.0" }, "require-dev": { "nikic/php-parser": "^4.13.0", From afbe1e3235c51ee3f10ba4c8b32449099016ea02 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 21 Apr 2022 15:03:41 +0200 Subject: [PATCH 25/53] Bleeding edge - set checkDynamicProperties to true --- rules.neon | 1 + src/Rules/Classes/RequireParentConstructCallRule.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/rules.neon b/rules.neon index 12e6590b..1954035d 100644 --- a/rules.neon +++ b/rules.neon @@ -4,6 +4,7 @@ parameters: checkAlwaysTrueCheckTypeFunctionCall: true checkAlwaysTrueInstanceof: true checkAlwaysTrueStrictComparison: true + checkDynamicProperties: %featureToggles.bleedingEdge% checkExplicitMixedMissingReturn: true checkFunctionNameCase: true checkInternalClassCaseSensitivity: true diff --git a/src/Rules/Classes/RequireParentConstructCallRule.php b/src/Rules/Classes/RequireParentConstructCallRule.php index fd386b2e..1ad03ebb 100644 --- a/src/Rules/Classes/RequireParentConstructCallRule.php +++ b/src/Rules/Classes/RequireParentConstructCallRule.php @@ -10,6 +10,7 @@ use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use ReflectionClass; +use function property_exists; use function sprintf; class RequireParentConstructCallRule implements Rule @@ -79,7 +80,7 @@ public function processNode(Node $node, Scope $scope): array private function callsParentConstruct(Node $parserNode): bool { - if (!isset($parserNode->stmts)) { + if (!property_exists($parserNode, 'stmts')) { return false; } From f3ca6464eae640a556c69a02b3b77a2507475d2f Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 28 Apr 2022 09:20:09 +0200 Subject: [PATCH 26/53] Turn on checkAlwaysTrueLooseComparison --- composer.json | 2 +- rules.neon | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f9c8f0c3..ca9b50ee 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ ], "require": { "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.6.0" + "phpstan/phpstan": "^1.6.3" }, "require-dev": { "nikic/php-parser": "^4.13.0", diff --git a/rules.neon b/rules.neon index 1954035d..3a91eec0 100644 --- a/rules.neon +++ b/rules.neon @@ -4,6 +4,7 @@ parameters: checkAlwaysTrueCheckTypeFunctionCall: true checkAlwaysTrueInstanceof: true checkAlwaysTrueStrictComparison: true + checkAlwaysTrueLooseComparison: true checkDynamicProperties: %featureToggles.bleedingEdge% checkExplicitMixedMissingReturn: true checkFunctionNameCase: true From c0b61e25933ca27ff65c66971336dd6e5061d756 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Mon, 2 May 2022 13:06:04 +0200 Subject: [PATCH 27/53] RequireParentConstructCallRule - fix abstract constructors --- src/Rules/Classes/RequireParentConstructCallRule.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Rules/Classes/RequireParentConstructCallRule.php b/src/Rules/Classes/RequireParentConstructCallRule.php index 1ad03ebb..92e9e41c 100644 --- a/src/Rules/Classes/RequireParentConstructCallRule.php +++ b/src/Rules/Classes/RequireParentConstructCallRule.php @@ -39,6 +39,10 @@ public function processNode(Node $node, Scope $scope): array return []; } + if ($node->isAbstract()) { + return []; + } + $classReflection = $scope->getClassReflection()->getNativeReflection(); if ($classReflection->isInterface() || $classReflection->isAnonymous()) { return []; From 4855249ef99e26f4e7b872782f3f7d1eb3a69db2 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Mon, 2 May 2022 13:06:42 +0200 Subject: [PATCH 28/53] Require PHPStan 1.7.0 --- composer.json | 2 +- phpstan-baseline.neon | 10 ---------- src/Rules/Classes/RequireParentConstructCallRule.php | 6 ++++-- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index ca9b50ee..4cd7aa63 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ ], "require": { "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.6.3" + "phpstan/phpstan": "^1.7.0" }, "require-dev": { "nikic/php-parser": "^4.13.0", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c271301d..327481a5 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -62,16 +62,6 @@ parameters: count: 1 path: src/Rules/Classes/RequireParentConstructCallRule.php - - - message: "#^Method PHPStan\\\\Rules\\\\Classes\\\\RequireParentConstructCallRule\\:\\:getParentConstructorClass\\(\\) has parameter \\$classReflection with generic class ReflectionClass but does not specify its types\\: T$#" - count: 1 - path: src/Rules/Classes/RequireParentConstructCallRule.php - - - - message: "#^Method PHPStan\\\\Rules\\\\Classes\\\\RequireParentConstructCallRule\\:\\:getParentConstructorClass\\(\\) return type with generic class ReflectionClass does not specify its types\\: T$#" - count: 1 - path: src/Rules/Classes/RequireParentConstructCallRule.php - - message: "#^Class PHPStan\\\\Rules\\\\DisallowedConstructs\\\\DisallowedBacktickRule implements generic interface PHPStan\\\\Rules\\\\Rule but does not specify its types\\: TNodeType$#" count: 1 diff --git a/src/Rules/Classes/RequireParentConstructCallRule.php b/src/Rules/Classes/RequireParentConstructCallRule.php index 92e9e41c..c07e04e4 100644 --- a/src/Rules/Classes/RequireParentConstructCallRule.php +++ b/src/Rules/Classes/RequireParentConstructCallRule.php @@ -7,9 +7,10 @@ use PhpParser\Node\Name; use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Analyser\Scope; +use PHPStan\BetterReflection\Reflection\Adapter\ReflectionClass; +use PHPStan\BetterReflection\Reflection\Adapter\ReflectionEnum; use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; -use ReflectionClass; use function property_exists; use function sprintf; @@ -114,9 +115,10 @@ private function callsParentConstruct(Node $parserNode): bool } /** + * @param ReflectionClass|ReflectionEnum $classReflection * @return ReflectionClass|false */ - private function getParentConstructorClass(ReflectionClass $classReflection) + private function getParentConstructorClass($classReflection) { while ($classReflection->getParentClass() !== false) { $constructor = $classReflection->getParentClass()->hasMethod('__construct') ? $classReflection->getParentClass()->getMethod('__construct') : null; From 0c82c96f2a55d8b91bbc7ee6512c94f68a206b43 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Wed, 4 May 2022 17:20:40 +0200 Subject: [PATCH 29/53] Move IllegalConstructorMethodCallRule and IllegalConstructorStaticCallRule to phpstan-strict-rules --- rules.neon | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rules.neon b/rules.neon index 3a91eec0..48011c37 100644 --- a/rules.neon +++ b/rules.neon @@ -12,6 +12,8 @@ parameters: reportMaybesInMethodSignatures: true reportStaticMethodSignatures: true reportMaybesInPropertyPhpDocTypes: true + featureToggles: + illegalConstructorMethodCall: %featureToggles.bleedingEdge% rules: - PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule From 2058d105209e635372a3d128cc0abc5259db352b Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 9 May 2022 01:20:35 +0000 Subject: [PATCH 30/53] chore(deps): update dependency slevomat/coding-standard to v7.2.0 --- build-cs/composer.lock | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/build-cs/composer.lock b/build-cs/composer.lock index 5a10fffd..6e7fb818 100644 --- a/build-cs/composer.lock +++ b/build-cs/composer.lock @@ -151,16 +151,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.4.2", + "version": "1.5.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "4cb3021a4e10ffe3d5f94a4c34cf4b3f6de2fa3d" + "reference": "981cc368a216c988e862a75e526b6076987d1b50" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/4cb3021a4e10ffe3d5f94a4c34cf4b3f6de2fa3d", - "reference": "4cb3021a4e10ffe3d5f94a4c34cf4b3f6de2fa3d", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/981cc368a216c988e862a75e526b6076987d1b50", + "reference": "981cc368a216c988e862a75e526b6076987d1b50", "shasum": "" }, "require": { @@ -189,38 +189,38 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.4.2" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.5.1" }, - "time": "2022-03-30T13:33:37+00:00" + "time": "2022-05-05T11:32:40+00:00" }, { "name": "slevomat/coding-standard", - "version": "7.1", + "version": "7.2.0", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "b521bd358b5f7a7d69e9637fd139e036d8adeb6f" + "reference": "b4f96a8beea515d2d89141b7b9ad72f526d84071" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/b521bd358b5f7a7d69e9637fd139e036d8adeb6f", - "reference": "b521bd358b5f7a7d69e9637fd139e036d8adeb6f", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/b4f96a8beea515d2d89141b7b9ad72f526d84071", + "reference": "b4f96a8beea515d2d89141b7b9ad72f526d84071", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7", "php": "^7.2 || ^8.0", - "phpstan/phpdoc-parser": "^1.4.1", + "phpstan/phpdoc-parser": "^1.5.1", "squizlabs/php_codesniffer": "^3.6.2" }, "require-dev": { - "phing/phing": "2.17.2", + "phing/phing": "2.17.3", "php-parallel-lint/php-parallel-lint": "1.3.2", - "phpstan/phpstan": "1.4.10|1.5.2", + "phpstan/phpstan": "1.4.10|1.6.7", "phpstan/phpstan-deprecation-rules": "1.0.0", - "phpstan/phpstan-phpunit": "1.0.0|1.1.0", - "phpstan/phpstan-strict-rules": "1.1.0", - "phpunit/phpunit": "7.5.20|8.5.21|9.5.19" + "phpstan/phpstan-phpunit": "1.0.0|1.1.1", + "phpstan/phpstan-strict-rules": "1.2.3", + "phpunit/phpunit": "7.5.20|8.5.21|9.5.20" }, "type": "phpcodesniffer-standard", "extra": { @@ -240,7 +240,7 @@ "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", "support": { "issues": "https://github.com/slevomat/coding-standard/issues", - "source": "https://github.com/slevomat/coding-standard/tree/7.1" + "source": "https://github.com/slevomat/coding-standard/tree/7.2.0" }, "funding": [ { @@ -252,7 +252,7 @@ "type": "tidelift" } ], - "time": "2022-03-29T12:44:16+00:00" + "time": "2022-05-06T10:58:42+00:00" }, { "name": "squizlabs/php_codesniffer", From 110818b25899b15656407644290c35fc9511cba7 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 30 May 2022 01:49:09 +0000 Subject: [PATCH 31/53] chore(deps): update dependency slevomat/coding-standard to v7.2.1 --- build-cs/composer.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/build-cs/composer.lock b/build-cs/composer.lock index 6e7fb818..4bcc8de4 100644 --- a/build-cs/composer.lock +++ b/build-cs/composer.lock @@ -195,16 +195,16 @@ }, { "name": "slevomat/coding-standard", - "version": "7.2.0", + "version": "7.2.1", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "b4f96a8beea515d2d89141b7b9ad72f526d84071" + "reference": "aff06ae7a84e4534bf6f821dc982a93a5d477c90" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/b4f96a8beea515d2d89141b7b9ad72f526d84071", - "reference": "b4f96a8beea515d2d89141b7b9ad72f526d84071", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/aff06ae7a84e4534bf6f821dc982a93a5d477c90", + "reference": "aff06ae7a84e4534bf6f821dc982a93a5d477c90", "shasum": "" }, "require": { @@ -216,7 +216,7 @@ "require-dev": { "phing/phing": "2.17.3", "php-parallel-lint/php-parallel-lint": "1.3.2", - "phpstan/phpstan": "1.4.10|1.6.7", + "phpstan/phpstan": "1.4.10|1.7.1", "phpstan/phpstan-deprecation-rules": "1.0.0", "phpstan/phpstan-phpunit": "1.0.0|1.1.1", "phpstan/phpstan-strict-rules": "1.2.3", @@ -240,7 +240,7 @@ "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", "support": { "issues": "https://github.com/slevomat/coding-standard/issues", - "source": "https://github.com/slevomat/coding-standard/tree/7.2.0" + "source": "https://github.com/slevomat/coding-standard/tree/7.2.1" }, "funding": [ { @@ -252,7 +252,7 @@ "type": "tidelift" } ], - "time": "2022-05-06T10:58:42+00:00" + "time": "2022-05-25T10:58:12+00:00" }, { "name": "squizlabs/php_codesniffer", From 484a051232991222729648853f98a78029068bbf Mon Sep 17 00:00:00 2001 From: Matthias Nagel Date: Thu, 16 Jun 2022 14:55:53 +0200 Subject: [PATCH 32/53] Bleeding edge - rule to disallow loose comparisons --- rules.neon | 7 +++ .../DisallowedLooseComparisonRule.php | 44 +++++++++++++++++++ .../DisallowedLooseComparisonRuleTest.php | 35 +++++++++++++++ .../data/weak-comparison.php | 6 +++ 4 files changed, 92 insertions(+) create mode 100644 src/Rules/DisallowedConstructs/DisallowedLooseComparisonRule.php create mode 100644 tests/Rules/DisallowedConstructs/DisallowedLooseComparisonRuleTest.php create mode 100644 tests/Rules/DisallowedConstructs/data/weak-comparison.php diff --git a/rules.neon b/rules.neon index 48011c37..d70a9111 100644 --- a/rules.neon +++ b/rules.neon @@ -52,6 +52,10 @@ rules: - PHPStan\Rules\VariableVariables\VariableStaticPropertyFetchRule - PHPStan\Rules\VariableVariables\VariableVariablesRule +conditionalTags: + PHPStan\Rules\DisallowedConstructs\DisallowedLooseComparisonRule: + phpstan.rules.rule: %featureToggles.bleedingEdge% + services: - class: PHPStan\Rules\BooleansInConditions\BooleanRuleHelper @@ -71,3 +75,6 @@ services: universalObjectCratesClasses: %universalObjectCratesClasses% tags: - phpstan.rules.rule + + - + class: PHPStan\Rules\DisallowedConstructs\DisallowedLooseComparisonRule diff --git a/src/Rules/DisallowedConstructs/DisallowedLooseComparisonRule.php b/src/Rules/DisallowedConstructs/DisallowedLooseComparisonRule.php new file mode 100644 index 00000000..a1425c76 --- /dev/null +++ b/src/Rules/DisallowedConstructs/DisallowedLooseComparisonRule.php @@ -0,0 +1,44 @@ + + */ +class DisallowedLooseComparisonRule implements Rule +{ + + public function getNodeType(): string + { + return BinaryOp::class; + } + + public function processNode(Node $node, Scope $scope): array + { + if ($node instanceof Equal) { + return [ + RuleErrorBuilder::message( + 'Loose comparison via "==" is not allowed.' + )->tip('Use strict comparison via "===" instead.')->build(), + ]; + } + if ($node instanceof NotEqual) { + return [ + RuleErrorBuilder::message( + 'Loose comparison via "!=" is not allowed.' + )->tip('Use strict comparison via "!==" instead.')->build(), + ]; + } + + return []; + } + +} diff --git a/tests/Rules/DisallowedConstructs/DisallowedLooseComparisonRuleTest.php b/tests/Rules/DisallowedConstructs/DisallowedLooseComparisonRuleTest.php new file mode 100644 index 00000000..9e56b583 --- /dev/null +++ b/tests/Rules/DisallowedConstructs/DisallowedLooseComparisonRuleTest.php @@ -0,0 +1,35 @@ + + */ +class DisallowedLooseComparisonRuleTest extends RuleTestCase +{ + + protected function getRule(): Rule + { + return new DisallowedLooseComparisonRule(); + } + + public function testRule(): void + { + $this->analyse([__DIR__ . '/data/weak-comparison.php'], [ + [ + 'Loose comparison via "==" is not allowed.', + 3, + 'Use strict comparison via "===" instead.', + ], + [ + 'Loose comparison via "!=" is not allowed.', + 5, + 'Use strict comparison via "!==" instead.', + ], + ]); + } + +} diff --git a/tests/Rules/DisallowedConstructs/data/weak-comparison.php b/tests/Rules/DisallowedConstructs/data/weak-comparison.php new file mode 100644 index 00000000..2e7e3a97 --- /dev/null +++ b/tests/Rules/DisallowedConstructs/data/weak-comparison.php @@ -0,0 +1,6 @@ + Date: Fri, 17 Jun 2022 23:02:00 +0200 Subject: [PATCH 33/53] Require PHPStan 1.7.15 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4cd7aa63..9719717c 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ ], "require": { "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.7.0" + "phpstan/phpstan": "^1.7.15" }, "require-dev": { "nikic/php-parser": "^4.13.0", From f6586fa24e1decb20459f9e1e81531d9df8d7881 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Fri, 17 Jun 2022 23:03:13 +0200 Subject: [PATCH 34/53] Fix WrongCaseOfInheritedMethodRule --- phpstan-baseline.neon | 10 ---------- .../Methods/WrongCaseOfInheritedMethodRule.php | 15 ++++----------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 327481a5..899d271d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -102,16 +102,6 @@ parameters: count: 1 path: src/Rules/ForeachLoop/OverwriteVariablesWithForeachRule.php - - - message: "#^Class PHPStan\\\\Rules\\\\Methods\\\\WrongCaseOfInheritedMethodRule implements generic interface PHPStan\\\\Rules\\\\Rule but does not specify its types\\: TNodeType$#" - count: 1 - path: src/Rules/Methods/WrongCaseOfInheritedMethodRule.php - - - - message: "#^Parameter \\#1 \\$node \\(PhpParser\\\\Node\\\\Stmt\\\\ClassMethod\\) of method PHPStan\\\\Rules\\\\Methods\\\\WrongCaseOfInheritedMethodRule\\:\\:processNode\\(\\) should be contravariant with parameter \\$node \\(PhpParser\\\\Node\\) of method PHPStan\\\\Rules\\\\Rule\\\\:\\:processNode\\(\\)$#" - count: 1 - path: src/Rules/Methods/WrongCaseOfInheritedMethodRule.php - - message: "#^Class PHPStan\\\\Rules\\\\Operators\\\\OperandInArithmeticIncrementOrDecrementRule implements generic interface PHPStan\\\\Rules\\\\Rule but does not specify its types\\: TNodeType$#" count: 1 diff --git a/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php b/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php index 09388a2d..be62e245 100644 --- a/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php +++ b/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php @@ -3,14 +3,15 @@ namespace PHPStan\Rules\Methods; use PhpParser\Node; -use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Analyser\Scope; use PHPStan\Node\InClassMethodNode; use PHPStan\Reflection\ClassReflection; -use PHPStan\Reflection\MethodReflection; use PHPStan\Rules\Rule; use function sprintf; +/** + * @implements Rule + */ class WrongCaseOfInheritedMethodRule implements Rule { @@ -19,20 +20,12 @@ public function getNodeType(): string return InClassMethodNode::class; } - /** - * @param ClassMethod $node - * @return string[] - */ public function processNode( Node $node, Scope $scope ): array { - $methodReflection = $scope->getFunction(); - if (!$methodReflection instanceof MethodReflection) { - return []; - } - + $methodReflection = $node->getMethodReflection(); $declaringClass = $methodReflection->getDeclaringClass(); $messages = []; From 543675a9be82d4befb9ca0bd8cdc9d211665037f Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Fri, 24 Jun 2022 08:47:20 +0200 Subject: [PATCH 35/53] Fix workflow --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 38309f6a..ab305821 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ on: pull_request: push: branches: - - "1.2.x" + - "1.3.x" jobs: lint: From a885399cc245e364249a187fc4ab16dd7ecfc56b Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Wed, 13 Jul 2022 12:52:35 +0200 Subject: [PATCH 36/53] Create tag workflow --- .github/workflows/create-tag.yml | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/create-tag.yml diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml new file mode 100644 index 00000000..8452d986 --- /dev/null +++ b/.github/workflows/create-tag.yml @@ -0,0 +1,53 @@ +# https://help.github.com/en/categories/automating-your-workflow-with-github-actions + +name: "Create tag" + +on: + # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch + workflow_dispatch: + inputs: + version: + description: 'Next version' + required: true + default: 'patch' + type: choice + options: + - patch + - minor + +jobs: + create-tag: + name: "Create tag" + runs-on: "ubuntu-latest" + steps: + - name: "Checkout" + uses: actions/checkout@v3 + with: + fetch-depth: 0 + token: ${{ secrets.PHPSTAN_BOT_TOKEN }} + + - name: 'Get Previous tag' + id: previoustag + uses: "WyriHaximus/github-action-get-previous-tag@v1" + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + + - name: 'Get next versions' + id: semvers + uses: "WyriHaximus/github-action-next-semvers@v1" + with: + version: ${{ steps.previoustag.outputs.tag }} + + - name: "Create new minor tag" + uses: rickstaa/action-create-tag@v1 + if: inputs.version == 'minor' + with: + tag: ${{ steps.semvers.outputs.minor }} + message: ${{ steps.semvers.outputs.minor }} + + - name: "Create new patch tag" + uses: rickstaa/action-create-tag@v1 + if: inputs.version == 'patch' + with: + tag: ${{ steps.semvers.outputs.patch }} + message: ${{ steps.semvers.outputs.patch }} From 6ec8ce72032f30b36669235df290de261a9a73ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Mirtes?= Date: Tue, 19 Jul 2022 13:14:07 +0200 Subject: [PATCH 37/53] Update build.yml --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ab305821..677bc218 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,6 +21,7 @@ jobs: - "7.4" - "8.0" - "8.1" + - "8.2" steps: - name: "Checkout" @@ -85,6 +86,7 @@ jobs: - "7.4" - "8.0" - "8.1" + - "8.2" dependencies: - "lowest" - "highest" @@ -127,6 +129,7 @@ jobs: - "7.4" - "8.0" - "8.1" + - "8.2" dependencies: - "lowest" - "highest" From f120c3b73e01e9330c8a0cfc408f0c3f94ac6a89 Mon Sep 17 00:00:00 2001 From: Martin Jonas Date: Sun, 24 Jul 2022 15:14:28 +0200 Subject: [PATCH 38/53] Configuration parameters to enable/disable rules --- README.md | 35 ++++++-- rules.neon | 253 ++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 240 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 304e26a8..5062ca56 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,25 @@ includes: ``` +## Disabling rules + +You can disable rules using configuration parameters: + +```neon +parameters: + strictRules: + booleansInConditions: false + uselessCast: false + requireParentConstructorCall: false + disallowedConstructs: false + overwriteVariablesWithLoop: false + closureUsesThis: false + matchingInheritedMethodNames: false + numericOperandsInArithmeticOperators: false + strictCalls: false + switchConditionsMatchingType: false + noVariableVariables: false +``` ## Enabling rules one-by-one @@ -79,13 +98,19 @@ services: ### With extension-installer -Unfortunately, by using `phpstan/extension-installer` you can't enable it one by one, ***but you can [ignore specific errors](https://phpstan.org/user-guide/ignoring-errors) instead***. +When using `phpstan/extension-installer` you can disable automatic loading of all rules by: + +```neon +parameters: + strictRules: + allRules: false +``` -For example: +Then you can enable individual rules by adding them as services just like without extension-installer (see above) or re-enable them by configuration parameters: ```neon parameters: - ignoreErrors: - - '#Construct empty\(\) is not allowed. Use more strict comparison.#' - - '#Call to function in_array\(\) requires parameter \#3 to be set.#' + strictRules: + allRules: false + booleansInConditions: true ``` diff --git a/rules.neon b/rules.neon index d70a9111..e74cba10 100644 --- a/rules.neon +++ b/rules.neon @@ -14,59 +14,116 @@ parameters: reportMaybesInPropertyPhpDocTypes: true featureToggles: illegalConstructorMethodCall: %featureToggles.bleedingEdge% + strictRules: + allRules: true + booleansInConditions: %strictRules.allRules% + uselessCast: %strictRules.allRules% + requireParentConstructorCall: %strictRules.allRules% + disallowedConstructs: %strictRules.allRules% + overwriteVariablesWithLoop: %strictRules.allRules% + closureUsesThis: %strictRules.allRules% + matchingInheritedMethodNames: %strictRules.allRules% + numericOperandsInArithmeticOperators: %strictRules.allRules% + strictCalls: %strictRules.allRules% + switchConditionsMatchingType: %strictRules.allRules% + noVariableVariables: %strictRules.allRules% -rules: - - PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule - - PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule - - PHPStan\Rules\BooleansInConditions\BooleanInBooleanOrRule - - PHPStan\Rules\BooleansInConditions\BooleanInElseIfConditionRule - - PHPStan\Rules\BooleansInConditions\BooleanInIfConditionRule - - PHPStan\Rules\BooleansInConditions\BooleanInTernaryOperatorRule - - PHPStan\Rules\Classes\RequireParentConstructCallRule - - PHPStan\Rules\DisallowedConstructs\DisallowedBacktickRule - - PHPStan\Rules\DisallowedConstructs\DisallowedEmptyRule - - PHPStan\Rules\DisallowedConstructs\DisallowedImplicitArrayCreationRule - - PHPStan\Rules\DisallowedConstructs\DisallowedShortTernaryRule - - PHPStan\Rules\ForeachLoop\OverwriteVariablesWithForeachRule - - PHPStan\Rules\ForLoop\OverwriteVariablesWithForLoopInitRule - - PHPStan\Rules\Functions\ClosureUsesThisRule - - PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule - - PHPStan\Rules\Operators\OperandInArithmeticPostDecrementRule - - PHPStan\Rules\Operators\OperandInArithmeticPostIncrementRule - - PHPStan\Rules\Operators\OperandInArithmeticPreDecrementRule - - PHPStan\Rules\Operators\OperandInArithmeticPreIncrementRule - - PHPStan\Rules\Operators\OperandsInArithmeticAdditionRule - - PHPStan\Rules\Operators\OperandsInArithmeticDivisionRule - - PHPStan\Rules\Operators\OperandsInArithmeticExponentiationRule - - PHPStan\Rules\Operators\OperandsInArithmeticModuloRule - - PHPStan\Rules\Operators\OperandsInArithmeticMultiplicationRule - - PHPStan\Rules\Operators\OperandsInArithmeticSubtractionRule - - PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsRule - - PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsCallableRule - - PHPStan\Rules\StrictCalls\StrictFunctionCallsRule - - PHPStan\Rules\SwitchConditions\MatchingTypeInSwitchCaseConditionRule - - PHPStan\Rules\VariableVariables\VariableMethodCallRule - - PHPStan\Rules\VariableVariables\VariableMethodCallableRule - - PHPStan\Rules\VariableVariables\VariableStaticMethodCallRule - - PHPStan\Rules\VariableVariables\VariableStaticMethodCallableRule - - PHPStan\Rules\VariableVariables\VariableStaticPropertyFetchRule - - PHPStan\Rules\VariableVariables\VariableVariablesRule +parametersSchema: + strictRules: structure([ + allRules: bool(), + booleansInConditions: bool() + uselessCast: bool() + requireParentConstructorCall: bool() + disallowedConstructs: bool() + overwriteVariablesWithLoop: bool() + closureUsesThis: bool() + matchingInheritedMethodNames: bool() + numericOperandsInArithmeticOperators: bool() + strictCalls: bool() + switchConditionsMatchingType: bool() + noVariableVariables: bool() + ]) conditionalTags: PHPStan\Rules\DisallowedConstructs\DisallowedLooseComparisonRule: phpstan.rules.rule: %featureToggles.bleedingEdge% + PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule: + phpstan.rules.rule: %strictRules.booleansInConditions% + PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule: + phpstan.rules.rule: %strictRules.booleansInConditions% + PHPStan\Rules\BooleansInConditions\BooleanInBooleanOrRule: + phpstan.rules.rule: %strictRules.booleansInConditions% + PHPStan\Rules\BooleansInConditions\BooleanInElseIfConditionRule: + phpstan.rules.rule: %strictRules.booleansInConditions% + PHPStan\Rules\BooleansInConditions\BooleanInIfConditionRule: + phpstan.rules.rule: %strictRules.booleansInConditions% + PHPStan\Rules\BooleansInConditions\BooleanInTernaryOperatorRule: + phpstan.rules.rule: %strictRules.booleansInConditions% + PHPStan\Rules\Cast\UselessCastRule: + phpstan.rules.rule: %strictRules.uselessCast% + PHPStan\Rules\Classes\RequireParentConstructCallRule: + phpstan.rules.rule: %strictRules.requireParentConstructorCall% + PHPStan\Rules\DisallowedConstructs\DisallowedBacktickRule: + phpstan.rules.rule: %strictRules.disallowedConstructs% + PHPStan\Rules\DisallowedConstructs\DisallowedEmptyRule: + phpstan.rules.rule: %strictRules.disallowedConstructs% + PHPStan\Rules\DisallowedConstructs\DisallowedImplicitArrayCreationRule: + phpstan.rules.rule: %strictRules.disallowedConstructs% + PHPStan\Rules\DisallowedConstructs\DisallowedShortTernaryRule: + phpstan.rules.rule: %strictRules.disallowedConstructs% + PHPStan\Rules\ForeachLoop\OverwriteVariablesWithForeachRule: + phpstan.rules.rule: %strictRules.overwriteVariablesWithLoop% + PHPStan\Rules\ForLoop\OverwriteVariablesWithForLoopInitRule: + phpstan.rules.rule: %strictRules.overwriteVariablesWithLoop% + PHPStan\Rules\Functions\ClosureUsesThisRule: + phpstan.rules.rule: %strictRules.closureUsesThis% + PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule: + phpstan.rules.rule: %strictRules.matchingInheritedMethodNames% + PHPStan\Rules\Operators\OperandInArithmeticPostDecrementRule: + phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators% + PHPStan\Rules\Operators\OperandInArithmeticPostIncrementRule: + phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators% + PHPStan\Rules\Operators\OperandInArithmeticPreDecrementRule: + phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators% + PHPStan\Rules\Operators\OperandInArithmeticPreIncrementRule: + phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators% + PHPStan\Rules\Operators\OperandsInArithmeticAdditionRule: + phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators% + PHPStan\Rules\Operators\OperandsInArithmeticDivisionRule: + phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators% + PHPStan\Rules\Operators\OperandsInArithmeticExponentiationRule: + phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators% + PHPStan\Rules\Operators\OperandsInArithmeticModuloRule: + phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators% + PHPStan\Rules\Operators\OperandsInArithmeticMultiplicationRule: + phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators% + PHPStan\Rules\Operators\OperandsInArithmeticSubtractionRule: + phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators% + PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsRule: + phpstan.rules.rule: %strictRules.strictCalls% + PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsCallableRule: + phpstan.rules.rule: %strictRules.strictCalls% + PHPStan\Rules\StrictCalls\StrictFunctionCallsRule: + phpstan.rules.rule: %strictRules.strictCalls% + PHPStan\Rules\SwitchConditions\MatchingTypeInSwitchCaseConditionRule: + phpstan.rules.rule: %strictRules.switchConditionsMatchingType% + PHPStan\Rules\VariableVariables\VariableMethodCallRule: + phpstan.rules.rule: %strictRules.noVariableVariables% + PHPStan\Rules\VariableVariables\VariableMethodCallableRule: + phpstan.rules.rule: %strictRules.noVariableVariables% + PHPStan\Rules\VariableVariables\VariableStaticMethodCallRule: + phpstan.rules.rule: %strictRules.noVariableVariables% + PHPStan\Rules\VariableVariables\VariableStaticMethodCallableRule: + phpstan.rules.rule: %strictRules.noVariableVariables% + PHPStan\Rules\VariableVariables\VariableStaticPropertyFetchRule: + phpstan.rules.rule: %strictRules.noVariableVariables% + PHPStan\Rules\VariableVariables\VariableVariablesRule: + phpstan.rules.rule: %strictRules.noVariableVariables% services: - class: PHPStan\Rules\BooleansInConditions\BooleanRuleHelper - - - class: PHPStan\Rules\Cast\UselessCastRule - arguments: - treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain% - tags: - - phpstan.rules.rule - - class: PHPStan\Rules\Operators\OperatorRuleHelper - @@ -78,3 +135,113 @@ services: - class: PHPStan\Rules\DisallowedConstructs\DisallowedLooseComparisonRule + + - + class: PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule + + - + class: PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule + + - + class: PHPStan\Rules\BooleansInConditions\BooleanInBooleanOrRule + + - + class: PHPStan\Rules\BooleansInConditions\BooleanInElseIfConditionRule + + - + class: PHPStan\Rules\BooleansInConditions\BooleanInIfConditionRule + + - + class: PHPStan\Rules\BooleansInConditions\BooleanInTernaryOperatorRule + + - + class: PHPStan\Rules\Cast\UselessCastRule + arguments: + treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain% + + - + class: PHPStan\Rules\Classes\RequireParentConstructCallRule + + - + class: PHPStan\Rules\DisallowedConstructs\DisallowedBacktickRule + + - + class: PHPStan\Rules\DisallowedConstructs\DisallowedEmptyRule + + - + class: PHPStan\Rules\DisallowedConstructs\DisallowedImplicitArrayCreationRule + + - + class: PHPStan\Rules\DisallowedConstructs\DisallowedShortTernaryRule + + - + class: PHPStan\Rules\ForeachLoop\OverwriteVariablesWithForeachRule + + - + class: PHPStan\Rules\ForLoop\OverwriteVariablesWithForLoopInitRule + + - + class: PHPStan\Rules\Functions\ClosureUsesThisRule + + - + class: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule + + - + class: PHPStan\Rules\Operators\OperandInArithmeticPostDecrementRule + + - + class: PHPStan\Rules\Operators\OperandInArithmeticPostIncrementRule + + - + class: PHPStan\Rules\Operators\OperandInArithmeticPreDecrementRule + + - + class: PHPStan\Rules\Operators\OperandInArithmeticPreIncrementRule + + - + class: PHPStan\Rules\Operators\OperandsInArithmeticAdditionRule + + - + class: PHPStan\Rules\Operators\OperandsInArithmeticDivisionRule + + - + class: PHPStan\Rules\Operators\OperandsInArithmeticExponentiationRule + + - + class: PHPStan\Rules\Operators\OperandsInArithmeticModuloRule + + - + class: PHPStan\Rules\Operators\OperandsInArithmeticMultiplicationRule + + - + class: PHPStan\Rules\Operators\OperandsInArithmeticSubtractionRule + + - + class: PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsRule + + - + class: PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsCallableRule + + - + class: PHPStan\Rules\StrictCalls\StrictFunctionCallsRule + + - + class: PHPStan\Rules\SwitchConditions\MatchingTypeInSwitchCaseConditionRule + + - + class: PHPStan\Rules\VariableVariables\VariableMethodCallRule + + - + class: PHPStan\Rules\VariableVariables\VariableMethodCallableRule + + - + class: PHPStan\Rules\VariableVariables\VariableStaticMethodCallRule + + - + class: PHPStan\Rules\VariableVariables\VariableStaticMethodCallableRule + + - + class: PHPStan\Rules\VariableVariables\VariableStaticPropertyFetchRule + + - + class: PHPStan\Rules\VariableVariables\VariableVariablesRule From 8019e79968be592bd9b09b18f279d1834b697571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Mirtes?= Date: Tue, 23 Aug 2022 17:04:03 +0200 Subject: [PATCH 39/53] Update README.md --- README.md | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 5062ca56..0a0b3397 100644 --- a/README.md +++ b/README.md @@ -79,26 +79,7 @@ parameters: If you don't want to start using all the available strict rules at once but only one or two, you can! -### Without extension-installer - -Just don't include the whole `rules.neon` from this package in your configuration, but look at its contents and copy only the rules you want to your configuration under the `services` key: - -```neon -services: - - - class: PHPStan\Rules\StrictCalls\StrictFunctionCallsRule - tags: - - phpstan.rules.rule - - - - class: PHPStan\Rules\SwitchConditions\MatchingTypeInSwitchCaseConditionRule - tags: - - phpstan.rules.rule -``` - -### With extension-installer - -When using `phpstan/extension-installer` you can disable automatic loading of all rules by: +You can disable all rules from the included `rules.neon` with: ```neon parameters: @@ -106,7 +87,7 @@ parameters: allRules: false ``` -Then you can enable individual rules by adding them as services just like without extension-installer (see above) or re-enable them by configuration parameters: +Then you can re-enable individual rules with configuration parameters: ```neon parameters: From a73b39739b5e165a7a40075ecf05c4385f6c0d1b Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Tue, 23 Aug 2022 17:07:03 +0200 Subject: [PATCH 40/53] Update workflow --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 677bc218..8d7d7aa8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ on: pull_request: push: branches: - - "1.3.x" + - "1.4.x" jobs: lint: From 6f0133dae1ed2d5fc674ad8324441c563720a0d3 Mon Sep 17 00:00:00 2001 From: Martin Herndl Date: Tue, 23 Aug 2022 20:36:15 +0200 Subject: [PATCH 41/53] Add regression test for non-looping loops --- composer.json | 2 +- tests/Rules/Operators/data/increment-decrement.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9719717c..3f7d80ca 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ ], "require": { "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.7.15" + "phpstan/phpstan": "^1.8.3" }, "require-dev": { "nikic/php-parser": "^4.13.0", diff --git a/tests/Rules/Operators/data/increment-decrement.php b/tests/Rules/Operators/data/increment-decrement.php index f4539f19..bdb97c5f 100644 --- a/tests/Rules/Operators/data/increment-decrement.php +++ b/tests/Rules/Operators/data/increment-decrement.php @@ -58,3 +58,12 @@ ++$mixed; ++$union; })(); + + +function (): void { + for ($i = 5; $i < 4; $i++) { + } + + for ($y = 0; $y < 0; $y++) { + } +}; From 749afc74f4e3190448c54bdd53d1ca015491191d Mon Sep 17 00:00:00 2001 From: Martin Jonas Date: Thu, 25 Aug 2022 16:57:41 +0200 Subject: [PATCH 42/53] Configuration parameters to enable/disable rules - fix for VariablePropertyFetchRule --- rules.neon | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rules.neon b/rules.neon index e74cba10..f7fa3e14 100644 --- a/rules.neon +++ b/rules.neon @@ -119,6 +119,8 @@ conditionalTags: phpstan.rules.rule: %strictRules.noVariableVariables% PHPStan\Rules\VariableVariables\VariableVariablesRule: phpstan.rules.rule: %strictRules.noVariableVariables% + PHPStan\Rules\VariableVariables\VariablePropertyFetchRule: + phpstan.rules.rule: %strictRules.noVariableVariables% services: - @@ -126,12 +128,11 @@ services: - class: PHPStan\Rules\Operators\OperatorRuleHelper + - class: PHPStan\Rules\VariableVariables\VariablePropertyFetchRule arguments: universalObjectCratesClasses: %universalObjectCratesClasses% - tags: - - phpstan.rules.rule - class: PHPStan\Rules\DisallowedConstructs\DisallowedLooseComparisonRule From 4e57160a710dea304fbd1a177ce38edd9b3848db Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 25 Aug 2022 17:04:21 +0200 Subject: [PATCH 43/53] Revert "Add regression test for non-looping loops" This reverts commit 6f0133dae1ed2d5fc674ad8324441c563720a0d3. --- composer.json | 2 +- tests/Rules/Operators/data/increment-decrement.php | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 3f7d80ca..9719717c 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ ], "require": { "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.8.3" + "phpstan/phpstan": "^1.7.15" }, "require-dev": { "nikic/php-parser": "^4.13.0", diff --git a/tests/Rules/Operators/data/increment-decrement.php b/tests/Rules/Operators/data/increment-decrement.php index bdb97c5f..f4539f19 100644 --- a/tests/Rules/Operators/data/increment-decrement.php +++ b/tests/Rules/Operators/data/increment-decrement.php @@ -58,12 +58,3 @@ ++$mixed; ++$union; })(); - - -function (): void { - for ($i = 5; $i < 4; $i++) { - } - - for ($y = 0; $y < 0; $y++) { - } -}; From 1f3b6491b8c8d92b266722dbfd9f882f98385724 Mon Sep 17 00:00:00 2001 From: Martin Herndl Date: Tue, 23 Aug 2022 20:36:15 +0200 Subject: [PATCH 44/53] Add regression test for non-looping loops --- composer.json | 2 +- tests/Rules/Operators/data/increment-decrement.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9719717c..3f7d80ca 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ ], "require": { "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.7.15" + "phpstan/phpstan": "^1.8.3" }, "require-dev": { "nikic/php-parser": "^4.13.0", diff --git a/tests/Rules/Operators/data/increment-decrement.php b/tests/Rules/Operators/data/increment-decrement.php index f4539f19..bdb97c5f 100644 --- a/tests/Rules/Operators/data/increment-decrement.php +++ b/tests/Rules/Operators/data/increment-decrement.php @@ -58,3 +58,12 @@ ++$mixed; ++$union; })(); + + +function (): void { + for ($i = 5; $i < 4; $i++) { + } + + for ($y = 0; $y < 0; $y++) { + } +}; From 431b3d6e8040075de196680cd5bc95735987b4ae Mon Sep 17 00:00:00 2001 From: n-ogawa Date: Fri, 26 Aug 2022 23:56:40 +0900 Subject: [PATCH 45/53] Fix wrong error when function is rebound. --- src/Rules/Functions/ClosureUsesThisRule.php | 4 ++++ tests/Rules/Functions/data/closure-uses-this.php | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Rules/Functions/ClosureUsesThisRule.php b/src/Rules/Functions/ClosureUsesThisRule.php index eab861db..fbce62f9 100644 --- a/src/Rules/Functions/ClosureUsesThisRule.php +++ b/src/Rules/Functions/ClosureUsesThisRule.php @@ -27,6 +27,10 @@ public function processNode(Node $node, Scope $scope): array return []; } + if ($scope->isInClosureBind()) { + return []; + } + $messages = []; foreach ($node->uses as $closureUse) { $varType = $scope->getType($closureUse->var); diff --git a/tests/Rules/Functions/data/closure-uses-this.php b/tests/Rules/Functions/data/closure-uses-this.php index e298303d..f7ca0b66 100644 --- a/tests/Rules/Functions/data/closure-uses-this.php +++ b/tests/Rules/Functions/data/closure-uses-this.php @@ -21,6 +21,9 @@ public function doFoo() $f = static function () use ($that) { // ok }; - } + $f = \Closure::bind(function () use ($that) { // ok + + }, null, Foo::class); + } } From 23e5f377ee6395a1a04842d3d6ed4bd25e7b44a6 Mon Sep 17 00:00:00 2001 From: Martin Jonas Date: Wed, 21 Sep 2022 10:30:01 +0200 Subject: [PATCH 46/53] Configuration option strictRules.disallowedLooseComparsion --- README.md | 1 + composer.json | 2 +- rules.neon | 28 +++++++++++++++------------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 0a0b3397..246c0c84 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ You can disable rules using configuration parameters: ```neon parameters: strictRules: + disallowedLooseComparison: false booleansInConditions: false uselessCast: false requireParentConstructorCall: false diff --git a/composer.json b/composer.json index 3f7d80ca..11dff8e4 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ ], "require": { "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.8.3" + "phpstan/phpstan": "^1.8.6" }, "require-dev": { "nikic/php-parser": "^4.13.0", diff --git a/rules.neon b/rules.neon index f7fa3e14..7dadfaaa 100644 --- a/rules.neon +++ b/rules.neon @@ -16,6 +16,7 @@ parameters: illegalConstructorMethodCall: %featureToggles.bleedingEdge% strictRules: allRules: true + disallowedLooseComparison: [%strictRules.allRules%, %featureToggles.bleedingEdge%] booleansInConditions: %strictRules.allRules% uselessCast: %strictRules.allRules% requireParentConstructorCall: %strictRules.allRules% @@ -30,23 +31,24 @@ parameters: parametersSchema: strictRules: structure([ - allRules: bool(), - booleansInConditions: bool() - uselessCast: bool() - requireParentConstructorCall: bool() - disallowedConstructs: bool() - overwriteVariablesWithLoop: bool() - closureUsesThis: bool() - matchingInheritedMethodNames: bool() - numericOperandsInArithmeticOperators: bool() - strictCalls: bool() - switchConditionsMatchingType: bool() - noVariableVariables: bool() + allRules: anyOf(bool(), arrayOf(bool())), + disallowedLooseComparison: anyOf(bool(), arrayOf(bool())), + booleansInConditions: anyOf(bool(), arrayOf(bool())) + uselessCast: anyOf(bool(), arrayOf(bool())) + requireParentConstructorCall: anyOf(bool(), arrayOf(bool())) + disallowedConstructs: anyOf(bool(), arrayOf(bool())) + overwriteVariablesWithLoop: anyOf(bool(), arrayOf(bool())) + closureUsesThis: anyOf(bool(), arrayOf(bool())) + matchingInheritedMethodNames: anyOf(bool(), arrayOf(bool())) + numericOperandsInArithmeticOperators: anyOf(bool(), arrayOf(bool())) + strictCalls: anyOf(bool(), arrayOf(bool())) + switchConditionsMatchingType: anyOf(bool(), arrayOf(bool())) + noVariableVariables: anyOf(bool(), arrayOf(bool())) ]) conditionalTags: PHPStan\Rules\DisallowedConstructs\DisallowedLooseComparisonRule: - phpstan.rules.rule: %featureToggles.bleedingEdge% + phpstan.rules.rule: %strictRules.disallowedLooseComparison% PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule: phpstan.rules.rule: %strictRules.booleansInConditions% PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule: From 00dd4fad4671a56c985847b2c8b5ce6c28665488 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Mon, 3 Oct 2022 15:24:08 +0200 Subject: [PATCH 47/53] Fix build --- composer.json | 2 +- phpstan.neon | 17 ----------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/composer.json b/composer.json index 11dff8e4..624d6d00 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ ], "require": { "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.8.6" + "phpstan/phpstan": "^1.9.0" }, "require-dev": { "nikic/php-parser": "^4.13.0", diff --git a/phpstan.neon b/phpstan.neon index 717a8b30..5df5c578 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -8,20 +8,3 @@ includes: parameters: excludePaths: - tests/*/data/* - -services: - scopeIsInClass: - class: PHPStan\Internal\ScopeIsInClassTypeSpecifyingExtension - arguments: - isInMethodName: isInClass - removeNullMethodName: getClassReflection - tags: - - phpstan.typeSpecifier.methodTypeSpecifyingExtension - - scopeIsInTrait: - class: PHPStan\Internal\ScopeIsInClassTypeSpecifyingExtension - arguments: - isInMethodName: isInTrait - removeNullMethodName: getTraitReflection - tags: - - phpstan.typeSpecifier.methodTypeSpecifyingExtension From 5a05cc46f4b41dbac0388d641be7b2b73daa3992 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Wed, 12 Oct 2022 10:37:52 +0200 Subject: [PATCH 48/53] Fix test --- tests/Rules/Cast/UselessCastRuleTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Rules/Cast/UselessCastRuleTest.php b/tests/Rules/Cast/UselessCastRuleTest.php index 92bf98cb..c1affdde 100644 --- a/tests/Rules/Cast/UselessCastRuleTest.php +++ b/tests/Rules/Cast/UselessCastRuleTest.php @@ -47,6 +47,7 @@ public function testUselessCast(): void [ 'Casting to string something that\'s already string.', 46, + 'Because the type is coming from a PHPDoc, you can turn off this check by setting treatPhpDocTypesAsCertain: false in your %configurationFile%.', ], ] ); From caf80fc819ba62b54dbdcd60e4ae1288ae2e46af Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 14 Nov 2022 02:10:57 +0000 Subject: [PATCH 49/53] Update metcalfc/changelog-generator action to v4 --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5fed0458..bac4a006 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: - name: Generate changelog id: changelog - uses: metcalfc/changelog-generator@v3.0.0 + uses: metcalfc/changelog-generator@v4.0.1 with: myToken: ${{ secrets.PHPSTAN_BOT_TOKEN }} From 4790ecb4c544d564d5ee549f998657dcb907387b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 12 Dec 2022 01:23:43 +0000 Subject: [PATCH 50/53] Update dessant/lock-threads action to v4 --- .github/workflows/lock-closed-issues.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lock-closed-issues.yml b/.github/workflows/lock-closed-issues.yml index a05d4173..4c7990df 100644 --- a/.github/workflows/lock-closed-issues.yml +++ b/.github/workflows/lock-closed-issues.yml @@ -8,7 +8,7 @@ jobs: lock: runs-on: ubuntu-latest steps: - - uses: dessant/lock-threads@v3 + - uses: dessant/lock-threads@v4 with: github-token: ${{ github.token }} issue-inactive-days: '31' From 86da8eba3149b563dcce4fd5560106dc5e74c3ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Mirtes?= Date: Mon, 19 Dec 2022 13:25:39 +0100 Subject: [PATCH 51/53] Create release-toot.yml --- .github/workflows/release-toot.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/release-toot.yml diff --git a/.github/workflows/release-toot.yml b/.github/workflows/release-toot.yml new file mode 100644 index 00000000..2af0f176 --- /dev/null +++ b/.github/workflows/release-toot.yml @@ -0,0 +1,21 @@ +name: Toot release + +# More triggers +# https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#release +on: + release: + types: [published] + +jobs: + toot: + runs-on: ubuntu-latest + steps: + - uses: cbrgm/mastodon-github-action@v1 + if: ${{ !github.event.repository.private }} + with: + # GitHub event payload + # https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#release + message: "New release: ${{ github.event.repository.name }} ${{ github.event.release.tag_name }} ${{ github.event.release.html_url }} #phpstan" + env: + MASTODON_URL: phpc.social + MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }} From 2ffa76a6c92679705e6ff18a05057658d0b4c91f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Mirtes?= Date: Tue, 20 Dec 2022 22:07:46 +0100 Subject: [PATCH 52/53] Update release-toot.yml --- .github/workflows/release-toot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-toot.yml b/.github/workflows/release-toot.yml index 2af0f176..6a1c8156 100644 --- a/.github/workflows/release-toot.yml +++ b/.github/workflows/release-toot.yml @@ -17,5 +17,5 @@ jobs: # https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#release message: "New release: ${{ github.event.repository.name }} ${{ github.event.release.tag_name }} ${{ github.event.release.html_url }} #phpstan" env: - MASTODON_URL: phpc.social + MASTODON_URL: https://phpc.social MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }} From 361f75b06066f3fdaba87c1f57bdb1ffc28d6f1d Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Wed, 11 Jan 2023 15:09:21 +0100 Subject: [PATCH 53/53] OperandsInArithmeticAdditionRule - allow benevolent unions of arrays --- composer.json | 2 +- src/Rules/Operators/OperandsInArithmeticAdditionRule.php | 7 ++----- tests/Rules/Operators/data/operators.php | 4 ++++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 624d6d00..a2424e49 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ ], "require": { "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.9.0" + "phpstan/phpstan": "^1.9.7" }, "require-dev": { "nikic/php-parser": "^4.13.0", diff --git a/src/Rules/Operators/OperandsInArithmeticAdditionRule.php b/src/Rules/Operators/OperandsInArithmeticAdditionRule.php index c0e5ca32..47323ffc 100644 --- a/src/Rules/Operators/OperandsInArithmeticAdditionRule.php +++ b/src/Rules/Operators/OperandsInArithmeticAdditionRule.php @@ -7,9 +7,8 @@ use PhpParser\Node\Expr\BinaryOp\Plus; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; -use PHPStan\Type\ArrayType; -use PHPStan\Type\MixedType; use PHPStan\Type\VerbosityLevel; +use function count; use function sprintf; class OperandsInArithmeticAdditionRule implements Rule @@ -36,9 +35,7 @@ public function processNode(Node $node, Scope $scope): array { $leftType = $scope->getType($node->left); $rightType = $scope->getType($node->right); - $mixedArrayType = new ArrayType(new MixedType(), new MixedType()); - - if ($mixedArrayType->isSuperTypeOf($leftType)->yes() && $mixedArrayType->isSuperTypeOf($rightType)->yes()) { + if (count($leftType->getArrays()) > 0 && count($rightType->getArrays()) > 0) { return []; } diff --git a/tests/Rules/Operators/data/operators.php b/tests/Rules/Operators/data/operators.php index ab132c83..92ec5930 100644 --- a/tests/Rules/Operators/data/operators.php +++ b/tests/Rules/Operators/data/operators.php @@ -113,3 +113,7 @@ function (array $array, int $int, $mixed) { /** @var numeric-string $numericString */ $numericString = doFoo(); $numericString + 1; + +function (\ReflectionClass $ref): void { + print_r(class_parents($ref->getName()) + class_implements($ref->getName())); +};