Skip to content

Commit

Permalink
Improve LocalConstantFinder performance (#3652)
Browse files Browse the repository at this point in the history
* Improve LocalConstantFinder performance

* simplify

* typo

* fix typo
  • Loading branch information
staabm committed Apr 22, 2023
1 parent 6374ccd commit c935e91
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/PhpParser/NodeFinder/LocalConstantFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,28 @@ public function match(ClassConstFetch $classConstFetch): ?Const_
return null;
}

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

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 $this->findConstantByName($class, $constantName);
}

private function findConstantByName(Class_ $class, string $constatName): ?Const_
private function findConstantByName(Class_ $class, string $constantName): ?Const_
{
foreach ($class->getConstants() as $classConsts) {
foreach ($classConsts->consts as $const) {
if (! $this->nodeNameResolver->isName($const->name, $constatName)) {
if (! $this->nodeNameResolver->isName($const->name, $constantName)) {
continue;
}

Expand Down

0 comments on commit c935e91

Please sign in to comment.