Skip to content

Commit b99f9dc

Browse files
[perf] Skip reflection in RemoveUnusedPrivateMethodRector when no private method (#8579)
Co-authored-by: GitHub Action <actions@github.com>
1 parent f06cc08 commit b99f9dc

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎rules/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector.php‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ public function getNodeTypes(): array
8181
*/
8282
public function refactor(Node $node): ?Node
8383
{
84-
if ($node->getMethods() === []) {
84+
// unreliable to detect on anonymous class: doesn't make sense
85+
if ($node->isAnonymous()) {
8586
return null;
8687
}
8788

88-
// unreliable to detect on anonymous class: doesn't make sense
89-
if ($node->isAnonymous()) {
89+
if (! $this->hasPrivateMethod($node)) {
9090
return null;
9191
}
9292

@@ -145,6 +145,11 @@ public function refactor(Node $node): ?Node
145145
return null;
146146
}
147147

148+
private function hasPrivateMethod(Class_ $class): bool
149+
{
150+
return array_any($class->getMethods(), fn(ClassMethod $classMethod): bool => $classMethod->isPrivate());
151+
}
152+
148153
private function shouldSkip(ClassMethod $classMethod, ClassReflection $classReflection): bool
149154
{
150155
// unreliable to detect trait, interface: doesn't make sense

0 commit comments

Comments
 (0)