Skip to content

Commit 03b7d3f

Browse files
janedbalondrejmirtes
authored andcommitted
OtherMethodQueryBuilderParser: improve cache key
1 parent 2ca2c7a commit 03b7d3f

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/Type/Doctrine/QueryBuilder/OtherMethodQueryBuilderParser.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use PHPStan\Type\TypeTraverser;
2323
use PHPStan\Type\UnionType;
2424
use function is_array;
25+
use function sprintf;
2526

2627
class OtherMethodQueryBuilderParser
2728
{
@@ -35,7 +36,7 @@ class OtherMethodQueryBuilderParser
3536
/** @var Container */
3637
private $container;
3738

38-
/** @var array<string, array<string, list<QueryBuilderType>>> */
39+
/** @var array<string, list<QueryBuilderType>> */
3940
private $cache = [];
4041

4142
public function __construct(bool $descendIntoOtherMethods, Parser $parser, Container $container)
@@ -55,17 +56,20 @@ public function findQueryBuilderTypesInCalledMethod(Scope $scope, MethodReflecti
5556
}
5657

5758
$methodName = $methodReflection->getName();
59+
$className = $methodReflection->getDeclaringClass()->getName();
5860
$fileName = $methodReflection->getDeclaringClass()->getFileName();
5961
if ($fileName === null) {
6062
return [];
6163
}
6264

63-
if (isset($this->cache[$fileName][$methodName])) {
64-
return $this->cache[$fileName][$methodName];
65+
$cacheKey = $this->buildCacheKey($fileName, $className, $methodName);
66+
67+
if (isset($this->cache[$cacheKey])) {
68+
return $this->cache[$cacheKey];
6569
}
6670

6771
$nodes = $this->parser->parseFile($fileName);
68-
$classNode = $this->findClassNode($methodReflection->getDeclaringClass()->getName(), $nodes);
72+
$classNode = $this->findClassNode($className, $nodes);
6973
if ($classNode === null) {
7074
return [];
7175
}
@@ -108,7 +112,7 @@ public function findQueryBuilderTypesInCalledMethod(Scope $scope, MethodReflecti
108112
});
109113
});
110114

111-
$this->cache[$fileName][$methodName] = $queryBuilderTypes;
115+
$this->cache[$cacheKey] = $queryBuilderTypes;
112116

113117
return $queryBuilderTypes;
114118
}
@@ -169,4 +173,9 @@ private function findMethodNode(string $methodName, array $classStatements): ?Cl
169173
return null;
170174
}
171175

176+
private function buildCacheKey(string $fileName, string $declaringClassName, string $methodName): string
177+
{
178+
return sprintf('%s-%s-%s', $fileName, $declaringClassName, $methodName);
179+
}
180+
172181
}

0 commit comments

Comments
 (0)