Skip to content

Commit

Permalink
Improve LocalConstantFinder performance
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Apr 22, 2023
1 parent 59720a1 commit 5b96c09
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/PhpParser/NodeFinder/LocalConstantFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,22 @@ public function match(ClassConstFetch $classConstFetch): ?Const_
return null;
}

$constantClassType = $this->nodeTypeResolver->getType($classConstFetch->class);
if (! $constantClassType instanceof TypeWithClassName) {
$constatName = $this->nodeNameResolver->getName($classConstFetch->name);
if ($constatName === null) {
return null;
}
$const = $this->findConstantByName($class, $constatName);

if (! $this->nodeNameResolver->isName($class, $constantClassType->getClassName())) {
$constantClassType = $this->nodeTypeResolver->getType($classConstFetch->class);
if (! $constantClassType instanceof TypeWithClassName) {
return null;
}

$constatName = $this->nodeNameResolver->getName($classConstFetch->name);
if ($constatName === null) {
if (! $this->nodeNameResolver->isName($class, $constantClassType->getClassName())) {
return null;
}

return $this->findConstantByName($class, $constatName);
return $const;
}

private function findConstantByName(Class_ $class, string $constatName): ?Const_
Expand Down

0 comments on commit 5b96c09

Please sign in to comment.