Skip to content

Commit

Permalink
[Performance] Reduce ClassReflection lookup on RemoveUnusedPrivateMet…
Browse files Browse the repository at this point in the history
…hodRector (#4006)

* [Performance] Reduce ClassReflection lookup on RemoveUnusedPrivateMethodRector

* [Performance] Reduce ClassReflection lookup on RemoveUnusedPrivateMethodRector
  • Loading branch information
samsonasik committed May 28, 2023
1 parent 95d3dc9 commit 48991c6
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,14 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node
}

$hasChanged = false;
$classReflection = null;

foreach ($node->getMethods() as $classMethod) {
if ($this->shouldSkip($classMethod)) {
if (! $classReflection instanceof ClassReflection) {
$classReflection = $this->reflectionResolver->resolveClassReflection($classMethod);
}

if ($this->shouldSkip($classMethod, $classReflection)) {
continue;
}

Expand All @@ -99,9 +105,8 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node
return null;
}

private function shouldSkip(ClassMethod $classMethod): bool
private function shouldSkip(ClassMethod $classMethod, ?ClassReflection $classReflection): bool
{
$classReflection = $this->reflectionResolver->resolveClassReflection($classMethod);
if (! $classReflection instanceof ClassReflection) {
return true;
}
Expand Down

0 comments on commit 48991c6

Please sign in to comment.