From 7899cd766e6cb0ca566a784322892c5b87f2e099 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 2 Dec 2023 20:44:58 +0100 Subject: [PATCH 1/3] add fixture to skip, as abstract class on purpose method --- .../Fixture/skip_abstract_empty_class.php.inc | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector/Fixture/skip_abstract_empty_class.php.inc 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 @@ + Date: Sat, 2 Dec 2023 20:47:06 +0100 Subject: [PATCH 2/3] [TypeDeclaration] Skip return void in abstract empty class in AddVoidReturnTypeWhereNoReturnRector --- .../PrivatizeLocalGetterToPropertyRector.php | 6 +++++- .../AddVoidReturnTypeWhereNoReturnRector.php | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/rules/Privatization/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php b/rules/Privatization/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php index f427209b2dd..09baf44e9ea 100644 --- a/rules/Privatization/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php +++ b/rules/Privatization/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php @@ -81,7 +81,11 @@ public function refactor(Node $node): ?Node $hasChanged = false; $isFinal = $class->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..6c7893cb316 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 $functionLike): bool + { + $classReflection = $this->reflectionResolver->resolveClassReflection($functionLike); + if (! $classReflection instanceof ClassReflection) { + return false; + } + + return $classReflection->isAbstract(); + } } From b4559e69b0eaf32c02023d40cae9d3f7c8d06601 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sat, 2 Dec 2023 19:52:00 +0000 Subject: [PATCH 3/3] [ci-review] Rector Rectify --- .../ClassMethod/AddVoidReturnTypeWhereNoReturnRector.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector.php index 6c7893cb316..8c32d515bb1 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector.php @@ -130,9 +130,9 @@ private function isInsideFinalClass(ClassMethod $classMethod): bool return $classReflection->isFinalByKeyword(); } - private function isInsideAbstractClass(ClassMethod $functionLike): bool + private function isInsideAbstractClass(ClassMethod $classMethod): bool { - $classReflection = $this->reflectionResolver->resolveClassReflection($functionLike); + $classReflection = $this->reflectionResolver->resolveClassReflection($classMethod); if (! $classReflection instanceof ClassReflection) { return false; }