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 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/*', 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; }