From 9e9d6571f5245db4365fd081832be9b0b61562fc Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 10 Oct 2026 10:47:14 +0200 Subject: [PATCH 1/2] [perf] Skip reflection in RemoveUnusedPrivateMethodRector when class has no private method --- .../RemoveUnusedPrivateMethodRector.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector.php b/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector.php index c41ad3087e4..ad6ba47eeec 100644 --- a/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector.php +++ b/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector.php @@ -81,12 +81,12 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - if ($node->getMethods() === []) { + // unreliable to detect on anonymous class: doesn't make sense + if ($node->isAnonymous()) { return null; } - // unreliable to detect on anonymous class: doesn't make sense - if ($node->isAnonymous()) { + if (! $this->hasPrivateMethod($node)) { return null; } @@ -145,6 +145,17 @@ public function refactor(Node $node): ?Node return null; } + private function hasPrivateMethod(Class_ $class): bool + { + foreach ($class->getMethods() as $classMethod) { + if ($classMethod->isPrivate()) { + return true; + } + } + + return false; + } + private function shouldSkip(ClassMethod $classMethod, ClassReflection $classReflection): bool { // unreliable to detect trait, interface: doesn't make sense From cd17b858931b8da59628b9a3fffe51624dccd1c1 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sat, 10 Oct 2026 08:48:33 +0000 Subject: [PATCH 2/2] [ci-review] Rector Rectify --- .../ClassMethod/RemoveUnusedPrivateMethodRector.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector.php b/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector.php index ad6ba47eeec..fe03b9af361 100644 --- a/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector.php +++ b/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector.php @@ -147,13 +147,7 @@ public function refactor(Node $node): ?Node private function hasPrivateMethod(Class_ $class): bool { - foreach ($class->getMethods() as $classMethod) { - if ($classMethod->isPrivate()) { - return true; - } - } - - return false; + return array_any($class->getMethods(), fn(ClassMethod $classMethod): bool => $classMethod->isPrivate()); } private function shouldSkip(ClassMethod $classMethod, ClassReflection $classReflection): bool