diff --git a/rules-tests/Naming/Rector/ClassMethod/RenameParamToMatchTypeRector/Fixture/skip_override_vendor_param.php.inc b/rules-tests/Naming/Rector/ClassMethod/RenameParamToMatchTypeRector/Fixture/skip_override_vendor_param.php.inc new file mode 100644 index 00000000000..d229000e2f9 --- /dev/null +++ b/rules-tests/Naming/Rector/ClassMethod/RenameParamToMatchTypeRector/Fixture/skip_override_vendor_param.php.inc @@ -0,0 +1,13 @@ +shouldSkipClassMethodFromVendor($node)) { + return null; + } + $expectedName = $this->expectedNameResolver->resolveForParamIfNotYet($param); if ($expectedName === null) { continue; @@ -115,6 +123,43 @@ public function refactor(Node $node): ?Node return $node; } + private function shouldSkipClassMethodFromVendor(ClassMethod $classMethod): bool + { + if ($classMethod->isPrivate()) { + return false; + } + + $classReflection = $this->reflectionResolver->resolveClassReflection($classMethod); + if (! $classReflection instanceof ClassReflection) { + return false; + } + + $ancestors = array_filter( + $classReflection->getAncestors(), + fn (ClassReflection $ancestorClassReflection): bool => + $classReflection->getName() !== $ancestorClassReflection->getName() + ); + + $methodName = $this->getName($classMethod); + foreach ($ancestors as $ancestor) { + // internal + if ($ancestor->getFileName() === null) { + continue; + } + + if (! $ancestor->hasNativeMethod($methodName)) { + continue; + } + + $path = PathNormalizer::normalize($ancestor->getFileName()); + if (str_contains($path, '/vendor/')) { + return true; + } + } + + return false; + } + private function shouldSkipParam( Param $param, string $expectedName,