Skip to content

Commit 2ca2c7a

Browse files
janedbalondrejmirtes
authored andcommitted
Do not parse the same method multiple times
1 parent df6560f commit 2ca2c7a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Type/Doctrine/QueryBuilder/OtherMethodQueryBuilderParser.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class OtherMethodQueryBuilderParser
3535
/** @var Container */
3636
private $container;
3737

38+
/** @var array<string, array<string, list<QueryBuilderType>>> */
39+
private $cache = [];
40+
3841
public function __construct(bool $descendIntoOtherMethods, Parser $parser, Container $container)
3942
{
4043
$this->descendIntoOtherMethods = $descendIntoOtherMethods;
@@ -51,18 +54,23 @@ public function findQueryBuilderTypesInCalledMethod(Scope $scope, MethodReflecti
5154
return [];
5255
}
5356

57+
$methodName = $methodReflection->getName();
5458
$fileName = $methodReflection->getDeclaringClass()->getFileName();
5559
if ($fileName === null) {
5660
return [];
5761
}
5862

63+
if (isset($this->cache[$fileName][$methodName])) {
64+
return $this->cache[$fileName][$methodName];
65+
}
66+
5967
$nodes = $this->parser->parseFile($fileName);
6068
$classNode = $this->findClassNode($methodReflection->getDeclaringClass()->getName(), $nodes);
6169
if ($classNode === null) {
6270
return [];
6371
}
6472

65-
$methodNode = $this->findMethodNode($methodReflection->getName(), $classNode->stmts);
73+
$methodNode = $this->findMethodNode($methodName, $classNode->stmts);
6674
if ($methodNode === null || $methodNode->stmts === null) {
6775
return [];
6876
}
@@ -100,6 +108,8 @@ public function findQueryBuilderTypesInCalledMethod(Scope $scope, MethodReflecti
100108
});
101109
});
102110

111+
$this->cache[$fileName][$methodName] = $queryBuilderTypes;
112+
103113
return $queryBuilderTypes;
104114
}
105115

0 commit comments

Comments
 (0)