diff --git a/rules-tests/DowngradePhp80/Rector/FunctionLike/DowngradeUnionTypeDeclarationRector/Fixture/override_from_interface.php.inc b/rules-tests/DowngradePhp80/Rector/FunctionLike/DowngradeUnionTypeDeclarationRector/Fixture/override_from_interface.php.inc new file mode 100644 index 00000000..b3f8791f --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FunctionLike/DowngradeUnionTypeDeclarationRector/Fixture/override_from_interface.php.inc @@ -0,0 +1,38 @@ + +----- + diff --git a/rules-tests/DowngradePhp80/Rector/FunctionLike/DowngradeUnionTypeDeclarationRector/Source/Foo1.php b/rules-tests/DowngradePhp80/Rector/FunctionLike/DowngradeUnionTypeDeclarationRector/Source/Foo1.php new file mode 100644 index 00000000..60f839f0 --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FunctionLike/DowngradeUnionTypeDeclarationRector/Source/Foo1.php @@ -0,0 +1,7 @@ +classMethodWillChangeReturnTypes = [ // @todo how to make list complete? is the method list needed or can we use just class names? @@ -96,6 +100,29 @@ public function decorateReturn(ClassMethod|Function_|Closure|ArrowFunction $func return; } + $ancestors = array_filter( + $classReflection->getAncestors(), + static fn (ClassReflection $ancestor): bool => $classReflection->getName() !== $ancestor->getName() + ); + + foreach ($ancestors as $ancestor) { + $classLike = $this->astResolver->resolveClassFromClassReflection($ancestor); + if (! $classLike instanceof ClassLike) { + continue; + } + + $classMethod = $classLike->getMethod($functionLike->name->toString()); + if (! $classMethod instanceof ClassMethod) { + continue; + } + + $returnType = $classMethod->returnType; + if ($returnType instanceof Node && $returnType instanceof FullyQualified) { + $functionLike->returnType = new FullyQualified($returnType->toString()); + break; + } + } + if (! $this->isRequireReturnTypeWillChange($classReflection, $functionLike)) { return; }