From f0f2c2695cd7acd417e1d3556bdcb901a740fdb3 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 12 Nov 2025 23:56:08 +0700 Subject: [PATCH 1/3] Bump to PHPStan ^2.1.32 and ignore false positive instanceof in OR usage --- composer.json | 2 +- phpstan.neon | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fc59966c..26f65778 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ }, "require-dev": { "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^2.1.30", + "phpstan/phpstan": "^2.1.32", "phpstan/phpstan-webmozart-assert": "^2.0", "phpunit/phpunit": "^11.5", "rector/rector-src": "dev-main", diff --git a/phpstan.neon b/phpstan.neon index 2218519a..afc31744 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -67,3 +67,12 @@ parameters: - '#Asking about instanceof PHPStan\\.* is not covered by backward compatibility promise#' - '#Method Rector\\(.*?)\\Rector\\FuncCall\\(.*?)::refactor\(\) never returns \d so it can be removed from the return type#' + + # false positive intanceof in OR usage + - + identifier: instanceof.alwaysTrue + path: rules/DowngradePhp80/Rector/NullsafeMethodCall/DowngradeNullsafeToTernaryOperatorRector.php + + - + identifier: deadCode.unreachable + path: rules/DowngradePhp80/Rector/NullsafeMethodCall/DowngradeNullsafeToTernaryOperatorRector.php From 0effdc8a79da2f64233e2f37e20edf0a7c146c96 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 13 Nov 2025 00:00:38 +0700 Subject: [PATCH 2/3] ignore in rector --- rector.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rector.php b/rector.php index 1f6fe9ad..9a70c593 100644 --- a/rector.php +++ b/rector.php @@ -4,6 +4,8 @@ use Rector\CodingStyle\Rector\String_\UseClassKeywordForClassNameResolutionRector; use Rector\Config\RectorConfig; +use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector; +use Rector\DeadCode\Rector\If_\RemoveDeadInstanceOfRector; use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; use Rector\PHPUnit\Set\PHPUnitSetList; @@ -37,6 +39,16 @@ __DIR__ . '/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php', ], + RemoveAlwaysTrueIfConditionRector::class => [ + // false positive in or check usage + __DIR__ . '/rules/DowngradePhp80/Rector/NullsafeMethodCall/DowngradeNullsafeToTernaryOperatorRector.php', + ], + + RemoveDeadInstanceOfRector::class => [ + // false positive in or check usage + __DIR__ . '/rules/DowngradePhp80/Rector/NullsafeMethodCall/DowngradeNullsafeToTernaryOperatorRector.php', + ], + // test paths '**/Fixture/*', '**/Source/*', From 08a79e78154731fc6f346d7d07b97eb87e459897 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 13 Nov 2025 00:01:31 +0700 Subject: [PATCH 3/3] rectify --- .../FuncCall/DowngradePregUnmatchedAsNullConstantRector.php | 2 +- rules/DowngradePhp80/NodeAnalyzer/NamedToUnnamedArgs.php | 6 ++---- .../DowngradePhp80/NodeAnalyzer/UnnamedArgumentResolver.php | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php b/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php index 5bb3dc84..5447cca1 100644 --- a/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php +++ b/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php @@ -82,7 +82,7 @@ public function refactor(Node $node) $flagsExpr = $args[3]->value; if ($flagsExpr instanceof BitwiseOr) { - $this->bitwiseFlagCleaner->cleanFuncCall($funcCall, $flagsExpr, self::UNMATCHED_NULL_FLAG, null); + $this->bitwiseFlagCleaner->cleanFuncCall($funcCall, $flagsExpr, self::UNMATCHED_NULL_FLAG); if ($this->nodeComparator->areNodesEqual($flagsExpr, $args[3]->value)) { return null; } diff --git a/rules/DowngradePhp80/NodeAnalyzer/NamedToUnnamedArgs.php b/rules/DowngradePhp80/NodeAnalyzer/NamedToUnnamedArgs.php index 54e2beec..8f3f1567 100644 --- a/rules/DowngradePhp80/NodeAnalyzer/NamedToUnnamedArgs.php +++ b/rules/DowngradePhp80/NodeAnalyzer/NamedToUnnamedArgs.php @@ -56,8 +56,7 @@ public function fillFromNamedArgs( $currentArg->value, $currentArg->byRef, $currentArg->unpack, - [], - null + [] ); } } @@ -108,8 +107,7 @@ public function fillFromJumpedNamedArgs( $parameterReflection->passedByReference() ->yes(), $parameterReflection->isVariadic(), - [], - null + [] ); } diff --git a/rules/DowngradePhp80/NodeAnalyzer/UnnamedArgumentResolver.php b/rules/DowngradePhp80/NodeAnalyzer/UnnamedArgumentResolver.php index 68e7b47d..2e59ab71 100644 --- a/rules/DowngradePhp80/NodeAnalyzer/UnnamedArgumentResolver.php +++ b/rules/DowngradePhp80/NodeAnalyzer/UnnamedArgumentResolver.php @@ -45,7 +45,7 @@ public function resolveFromReflection( foreach ($currentArgs as $key => $arg) { if (! $arg->name instanceof Identifier) { - $unnamedArgs[$key] = new Arg($arg->value, $arg->byRef, $arg->unpack, [], null); + $unnamedArgs[$key] = new Arg($arg->value, $arg->byRef, $arg->unpack, []); continue; }