diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector/Fixture/skip_abstract_empty_class.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector/Fixture/skip_abstract_empty_class.php.inc new file mode 100644 index 00000000000..9c9166c26b9 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector/Fixture/skip_abstract_empty_class.php.inc @@ -0,0 +1,13 @@ +isFinal(); - $this->traverseNodesWithCallable($node, function (Node $node) use ($class, &$hasChanged, $isFinal): ?PropertyFetch { + $this->traverseNodesWithCallable($node, function (Node $node) use ( + $class, + &$hasChanged, + $isFinal + ): ?PropertyFetch { if (! $node instanceof MethodCall) { return null; } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector.php index 12b6468d03a..8c32d515bb1 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector.php @@ -117,7 +117,7 @@ private function shouldSkipClassMethod(ClassMethod|Function_|Closure $functionLi return ! $this->isInsideFinalClass($functionLike); } - return false; + return $this->isInsideAbstractClass($functionLike) && $functionLike->getStmts() === []; } private function isInsideFinalClass(ClassMethod $classMethod): bool @@ -129,4 +129,14 @@ private function isInsideFinalClass(ClassMethod $classMethod): bool return $classReflection->isFinalByKeyword(); } + + private function isInsideAbstractClass(ClassMethod $classMethod): bool + { + $classReflection = $this->reflectionResolver->resolveClassReflection($classMethod); + if (! $classReflection instanceof ClassReflection) { + return false; + } + + return $classReflection->isAbstract(); + } }