diff --git a/rules-tests/CodeQuality/Rector/Class_/StaticToSelfStaticMethodCallOnFinalClassRector/Fixture/parent_static_method.php.inc b/rules-tests/CodeQuality/Rector/Class_/StaticToSelfStaticMethodCallOnFinalClassRector/Fixture/parent_static_method.php.inc new file mode 100644 index 00000000000..afb0319859d --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Class_/StaticToSelfStaticMethodCallOnFinalClassRector/Fixture/parent_static_method.php.inc @@ -0,0 +1,31 @@ + +----- + diff --git a/rules-tests/CodeQuality/Rector/Class_/StaticToSelfStaticMethodCallOnFinalClassRector/Source/BaseClass.php b/rules-tests/CodeQuality/Rector/Class_/StaticToSelfStaticMethodCallOnFinalClassRector/Source/BaseClass.php new file mode 100644 index 00000000000..1f56d0e22b1 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Class_/StaticToSelfStaticMethodCallOnFinalClassRector/Source/BaseClass.php @@ -0,0 +1,11 @@ +getClassReflection(); - $this->traverseNodesWithCallable($node->stmts, function (Node $subNode) use (&$hasChanged, $node): ?StaticCall { + if (! $classReflection instanceof ClassReflection) { + return null; + } + + $this->traverseNodesWithCallable($node->stmts, function (Node $subNode) use (&$hasChanged, $classReflection): ?StaticCall { if (! $subNode instanceof StaticCall) { return null; } @@ -92,15 +100,15 @@ public function refactor(Node $node): ?Class_ } $methodName = (string) $this->getName($subNode->name); - $targetClassMethod = $node->getMethod($methodName); - // skip call non-existing method from current class to ensure transformation is safe - if (! $targetClassMethod instanceof ClassMethod) { + if (! $classReflection->hasNativeMethod($methodName)) { return null; } + $methodReflection = $classReflection->getNativeMethod($methodName); + // avoid overlapped change - if (! $targetClassMethod->isStatic()) { + if (! $methodReflection->isStatic()) { return null; }