diff --git a/rules-tests/Symfony61/Rector/Class_/MagicClosureTwigExtensionToNativeMethodsRector/Fixture/skip_external_non_static_method.php.inc b/rules-tests/Symfony61/Rector/Class_/MagicClosureTwigExtensionToNativeMethodsRector/Fixture/skip_external_non_static_method.php.inc new file mode 100644 index 000000000..cdd2901de --- /dev/null +++ b/rules-tests/Symfony61/Rector/Class_/MagicClosureTwigExtensionToNativeMethodsRector/Fixture/skip_external_non_static_method.php.inc @@ -0,0 +1,17 @@ +isNonStaticExternalClassCallable($arrayCallable, $scope)) { + return null; + } + $hasChanged = true; return new MethodCall($arrayCallable->getCallerExpr(), $arrayCallable->getMethod(), [ @@ -156,4 +163,25 @@ private function refactorClassMethod(ClassMethod $classMethod, Scope $scope): bo return $hasChanged; } + + private function isNonStaticExternalClassCallable(ArrayCallable $arrayCallable, Scope $scope): bool + { + if (! $arrayCallable->getCallerExpr() instanceof ClassConstFetch) { + return false; + } + + $className = $arrayCallable->getClass(); + if (! $this->reflectionProvider->hasClass($className)) { + return false; + } + + $classReflection = $this->reflectionProvider->getClass($className); + $methodName = $arrayCallable->getMethod(); + + if (! $classReflection->hasMethod($methodName)) { + return false; + } + + return ! $classReflection->getMethod($methodName, $scope)->isStatic(); + } }