diff --git a/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnTypeOverrideGuard.php b/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnTypeOverrideGuard.php index 8536236a866..c160055a682 100644 --- a/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnTypeOverrideGuard.php +++ b/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnTypeOverrideGuard.php @@ -104,7 +104,7 @@ private function isReturnTypeChangeAllowed(ClassMethod $classMethod, Scope $scop // nothing to check if (! $parentClassMethodReflection instanceof MethodReflection) { - return true; + return ! $this->parentClassMethodTypeOverrideGuard->hasParentClassMethod($classMethod); } $parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select( diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictParamRector/Fixture/from_parent_has_return.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictParamRector/Fixture/from_parent_has_return.php.inc new file mode 100644 index 00000000000..d90a3b163b6 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictParamRector/Fixture/from_parent_has_return.php.inc @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictParamRector/Fixture/parent_overridden.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictParamRector/Fixture/parent_overridden.php.inc new file mode 100644 index 00000000000..8e65a87da64 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictParamRector/Fixture/parent_overridden.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictParamRector/Fixture/skip_parent_overridden.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictParamRector/Fixture/skip_parent_overridden.php.inc deleted file mode 100644 index 4e965e586bf..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictParamRector/Fixture/skip_parent_overridden.php.inc +++ /dev/null @@ -1,15 +0,0 @@ -shouldSkipNode($node)) { + if ($this->shouldSkipNode($node, $scope)) { return null; } @@ -195,20 +195,14 @@ private function shouldSkipParam(Param $param, array $stmts): bool return $isParamModified; } - private function shouldSkipNode(ClassMethod|Function_|Closure $node): bool + private function shouldSkipNode(ClassMethod|Function_|Closure $node, Scope $scope): bool { if ($node->returnType !== null) { return true; } - if ($node instanceof ClassMethod) { - if ($this->parentClassMethodTypeOverrideGuard->hasParentClassMethod($node)) { - return true; - } - - if ($node->isMagic()) { - return true; - } + if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) { + return true; } $returnType = $this->returnTypeInferer->inferFunctionLike($node);