Skip to content

Commit

Permalink
[Ast] Improve AstResolver and ClassLikeAstResolver performance (#3714)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Apr 30, 2023
1 parent c3aca95 commit 8e1db4d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/PhpParser/AstResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ public function resolveClassFromName(string $className): Class_ | Trait_ | Inter
public function resolveClassMethodFromMethodReflection(MethodReflection $methodReflection): ?ClassMethod
{
$classReflection = $methodReflection->getDeclaringClass();

$classLikeName = $classReflection->getName();
$methodName = $methodReflection->getName();

$fileName = $classReflection->getFileName();

// probably native PHP method → un-parseable
Expand All @@ -92,6 +88,9 @@ public function resolveClassMethodFromMethodReflection(MethodReflection $methodR
return null;
}

$classLikeName = $classReflection->getName();
$methodName = $methodReflection->getName();

$classMethod = null;
$this->simpleCallableNodeTraverser->traverseNodesWithCallable(
$nodes,
Expand Down Expand Up @@ -131,8 +130,6 @@ public function resolveClassMethodOrFunctionFromCall(

public function resolveFunctionFromFunctionReflection(FunctionReflection $functionReflection): ?Function_
{
$functionName = $functionReflection->getName();

$fileName = $functionReflection->getFileName();
if ($fileName === null) {
return null;
Expand All @@ -143,7 +140,9 @@ public function resolveFunctionFromFunctionReflection(FunctionReflection $functi
return null;
}

$functionName = $functionReflection->getName();
$functionNode = null;

$this->simpleCallableNodeTraverser->traverseNodesWithCallable(
$nodes,
function (Node $node) use ($functionName, &$functionNode): ?int {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpParser/ClassLikeAstResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public function resolveClassFromClassReflection(
return null;
}

$className = $classReflection->getName();
$fileName = $classReflection->getFileName();

// probably internal class
Expand All @@ -51,6 +50,7 @@ public function resolveClassFromClassReflection(
return null;
}

$className = $classReflection->getName();
/** @var Class_|Trait_|Interface_|Enum_|null $classLike */
$classLike = $this->betterNodeFinder->findFirst(
$stmts,
Expand Down

0 comments on commit 8e1db4d

Please sign in to comment.