From c935e91d0c13084537217f7b538a91d03b8bd4f5 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 22 Apr 2023 18:20:50 +0200 Subject: [PATCH] Improve LocalConstantFinder performance (#3652) * Improve LocalConstantFinder performance * simplify * typo * fix typo --- src/PhpParser/NodeFinder/LocalConstantFinder.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/PhpParser/NodeFinder/LocalConstantFinder.php b/src/PhpParser/NodeFinder/LocalConstantFinder.php index f88daad5e26..fdadf54d488 100644 --- a/src/PhpParser/NodeFinder/LocalConstantFinder.php +++ b/src/PhpParser/NodeFinder/LocalConstantFinder.php @@ -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; }