diff --git a/rules/Php80/Rector/ClassMethod/AddParamBasedOnParentClassMethodRector.php b/rules/Php80/Rector/ClassMethod/AddParamBasedOnParentClassMethodRector.php index f0e5a6095c2..098ddfeb73e 100644 --- a/rules/Php80/Rector/ClassMethod/AddParamBasedOnParentClassMethodRector.php +++ b/rules/Php80/Rector/ClassMethod/AddParamBasedOnParentClassMethodRector.php @@ -130,11 +130,11 @@ public function refactor(Node $node): ?Node $scope = ScopeFetcher::fetch($node); $currentClassReflection = $scope->getClassReflection(); - $isPDO = $currentClassReflection instanceof ClassReflection && $currentClassReflection->is('PDO'); - // It relies on phpstorm stubs that define 2 kind of query method for both php 7.4 and php 8.0 // @see https://github.com/JetBrains/phpstorm-stubs/blob/e2e898a29929d2f520fe95bdb2109d8fa895ba4a/PDO/PDO.php#L1096-L1126 - if ($isPDO && $parentMethodReflection->getName() === 'query') { + if ($parentMethodReflection->getName() === 'query' + && $currentClassReflection instanceof ClassReflection + && $currentClassReflection->is('PDO')) { continue; } diff --git a/rules/Php80/Rector/Identical/StrEndsWithRector.php b/rules/Php80/Rector/Identical/StrEndsWithRector.php index eac7487378d..fd5f850b847 100644 --- a/rules/Php80/Rector/Identical/StrEndsWithRector.php +++ b/rules/Php80/Rector/Identical/StrEndsWithRector.php @@ -171,11 +171,6 @@ private function refactorSubstrCompare(BinaryOp $binaryOp): FuncCall|BooleanNot| return null; } - $expr = $funcCallAndExpr->getExpr(); - if (! $this->valueResolver->isValue($expr, 0)) { - return null; - } - $substrCompareFuncCall = $funcCallAndExpr->getFuncCall(); $args = $substrCompareFuncCall->getArgs(); @@ -183,6 +178,11 @@ private function refactorSubstrCompare(BinaryOp $binaryOp): FuncCall|BooleanNot| return null; } + $expr = $funcCallAndExpr->getExpr(); + if (! $this->valueResolver->isValue($expr, 0)) { + return null; + } + $haystack = $args[0]->value; $needle = $args[1]->value; $thirdArgValue = $args[2]->value; diff --git a/rules/Php81/Rector/MethodCall/MyCLabsMethodCallToEnumConstRector.php b/rules/Php81/Rector/MethodCall/MyCLabsMethodCallToEnumConstRector.php index b1b267b646b..59cc790c4b0 100644 --- a/rules/Php81/Rector/MethodCall/MyCLabsMethodCallToEnumConstRector.php +++ b/rules/Php81/Rector/MethodCall/MyCLabsMethodCallToEnumConstRector.php @@ -279,6 +279,10 @@ private function getEnumConstFetch(StaticCall $staticCall): null|ClassConstFetch private function refactorMethodCall(MethodCall $methodCall, string $methodName): null|PropertyFetch|Identical { + if (! in_array($methodName, ['getKey', 'getValue', 'equals'], true)) { + return null; + } + if (! $this->isObjectType($methodCall->var, new ObjectType('MyCLabs\Enum\Enum'))) { return null; } @@ -291,11 +295,7 @@ private function refactorMethodCall(MethodCall $methodCall, string $methodName): return $this->refactorGetValueMethodCall($methodCall); } - if ($methodName === 'equals') { - return $this->refactorEqualsMethodCall($methodCall); - } - - return null; + return $this->refactorEqualsMethodCall($methodCall); } private function shouldOmitEnumCase(string $enumCaseName): bool diff --git a/rules/Php81/Rector/MethodCall/SpatieEnumMethodCallToEnumConstRector.php b/rules/Php81/Rector/MethodCall/SpatieEnumMethodCallToEnumConstRector.php index 98ddb4bbd98..8ab21088997 100644 --- a/rules/Php81/Rector/MethodCall/SpatieEnumMethodCallToEnumConstRector.php +++ b/rules/Php81/Rector/MethodCall/SpatieEnumMethodCallToEnumConstRector.php @@ -127,27 +127,19 @@ private function refactorGetterToMethodCall(MethodCall $methodCall, string $prop private function refactorMethodCall(MethodCall $methodCall, string $methodName): null|PropertyFetch { - if (! $this->isObjectType($methodCall->var, new ObjectType(self::SPATIE_FQN))) { + if (! in_array($methodName, ['getName', 'label', 'getValue', 'value'], true)) { return null; } - if ($methodName === 'getName') { - return $this->refactorGetterToMethodCall($methodCall, 'name'); + if (! $this->isObjectType($methodCall->var, new ObjectType(self::SPATIE_FQN))) { + return null; } - if ($methodName === 'label') { + if (in_array($methodName, ['getName', 'label'], true)) { return $this->refactorGetterToMethodCall($methodCall, 'name'); } - if ($methodName === 'getValue') { - return $this->refactorGetterToMethodCall($methodCall, 'value'); - } - - if ($methodName === 'value') { - return $this->refactorGetterToMethodCall($methodCall, 'value'); - } - - return null; + return $this->refactorGetterToMethodCall($methodCall, 'value'); } private function shouldOmitEnumCase(string $enumCaseName): bool diff --git a/rules/Php83/Rector/ClassConst/AddTypeToConstRector.php b/rules/Php83/Rector/ClassConst/AddTypeToConstRector.php index c938b960c00..33997e9926f 100644 --- a/rules/Php83/Rector/ClassConst/AddTypeToConstRector.php +++ b/rules/Php83/Rector/ClassConst/AddTypeToConstRector.php @@ -88,7 +88,7 @@ public function refactor(Node $node): ?Class_ return null; } - $parentClassReflections = $this->getParentReflections($className); + $parentClassReflections = null; $hasChanged = false; @@ -104,11 +104,12 @@ public function refactor(Node $node): ?Class_ continue; } - if ($this->isConstGuardedByParents($constNode, $parentClassReflections)) { + if ($this->canBeInherited($classConst, $node)) { continue; } - if ($this->canBeInherited($classConst, $node)) { + $parentClassReflections ??= $this->getParentReflections($className); + if ($this->isConstGuardedByParents($constNode, $parentClassReflections)) { continue; } diff --git a/rules/Php84/Rector/FuncCall/AddEscapeArgumentRector.php b/rules/Php84/Rector/FuncCall/AddEscapeArgumentRector.php index b41e8c132cd..22de13f123d 100644 --- a/rules/Php84/Rector/FuncCall/AddEscapeArgumentRector.php +++ b/rules/Php84/Rector/FuncCall/AddEscapeArgumentRector.php @@ -81,10 +81,6 @@ public function refactor(Node $node): null|FuncCall|MethodCall return null; } - if (! $this->isObjectType($node->var, new ObjectType('SplFileObject'))) { - return null; - } - if ($this->shouldSkipNamedArg($node)) { return null; } @@ -97,6 +93,10 @@ public function refactor(Node $node): null|FuncCall|MethodCall return null; } + if (! $this->isObjectType($node->var, new ObjectType('SplFileObject'))) { + return null; + } + $node->args[count($node->getArgs())] = new Arg(new String_('\\'), name: new Identifier('escape')); return $node; }