Skip to content

Commit

Permalink
Do not parse the same method multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal authored and ondrejmirtes committed Jan 17, 2024
1 parent df6560f commit 2ca2c7a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Type/Doctrine/QueryBuilder/OtherMethodQueryBuilderParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class OtherMethodQueryBuilderParser
/** @var Container */
private $container;

/** @var array<string, array<string, list<QueryBuilderType>>> */
private $cache = [];

public function __construct(bool $descendIntoOtherMethods, Parser $parser, Container $container)
{
$this->descendIntoOtherMethods = $descendIntoOtherMethods;
Expand All @@ -51,18 +54,23 @@ public function findQueryBuilderTypesInCalledMethod(Scope $scope, MethodReflecti
return [];
}

$methodName = $methodReflection->getName();
$fileName = $methodReflection->getDeclaringClass()->getFileName();
if ($fileName === null) {
return [];
}

if (isset($this->cache[$fileName][$methodName])) {
return $this->cache[$fileName][$methodName];
}

$nodes = $this->parser->parseFile($fileName);
$classNode = $this->findClassNode($methodReflection->getDeclaringClass()->getName(), $nodes);
if ($classNode === null) {
return [];
}

$methodNode = $this->findMethodNode($methodReflection->getName(), $classNode->stmts);
$methodNode = $this->findMethodNode($methodName, $classNode->stmts);
if ($methodNode === null || $methodNode->stmts === null) {
return [];
}
Expand Down Expand Up @@ -100,6 +108,8 @@ public function findQueryBuilderTypesInCalledMethod(Scope $scope, MethodReflecti
});
});

$this->cache[$fileName][$methodName] = $queryBuilderTypes;

return $queryBuilderTypes;
}

Expand Down

0 comments on commit 2ca2c7a

Please sign in to comment.