Skip to content

Commit e25daa3

Browse files
committed
Merge remote-tracking branch 'origin/1.3.x' into 1.4.x
2 parents 6827950 + 9534fcd commit e25daa3

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/Type/Doctrine/QueryBuilder/OtherMethodQueryBuilderParser.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use PHPStan\Type\Type;
2222
use PHPStan\Type\TypeTraverser;
2323
use PHPStan\Type\UnionType;
24+
use function array_key_exists;
2425
use function is_array;
2526
use function sprintf;
2627

@@ -36,7 +37,11 @@ class OtherMethodQueryBuilderParser
3637
/** @var Container */
3738
private $container;
3839

39-
/** @var array<string, list<QueryBuilderType>> */
40+
/**
41+
* Null if the method is currently being processed
42+
*
43+
* @var array<string, list<QueryBuilderType>|null>
44+
*/
4045
private $cache = [];
4146

4247
public function __construct(bool $descendIntoOtherMethods, Parser $parser, Container $container)
@@ -64,10 +69,16 @@ public function findQueryBuilderTypesInCalledMethod(Scope $scope, MethodReflecti
6469

6570
$cacheKey = $this->buildCacheKey($fileName, $className, $methodName);
6671

67-
if (isset($this->cache[$cacheKey])) {
72+
if (array_key_exists($cacheKey, $this->cache)) {
73+
if ($this->cache[$cacheKey] === null) {
74+
return []; // recursion
75+
}
76+
6877
return $this->cache[$cacheKey];
6978
}
7079

80+
$this->cache[$cacheKey] = null;
81+
7182
$nodes = $this->parser->parseFile($fileName);
7283
$classNode = $this->findClassNode($className, $nodes);
7384
if ($classNode === null) {

tests/Type/Doctrine/data/QueryResult/queryBuilderExpressionTypeResolver.php

+15
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ private function adjustQueryBuilderToIndexByInt(QueryBuilder $qb): void
7171
$qb->indexBy('m', 'm.intColumn');
7272
}
7373

74+
private function getQueryBuilderRecursively(EntityManagerInterface $em): QueryBuilder
75+
{
76+
return $this->getQueryBuilderRecursively($em);
77+
}
78+
79+
private function getQueryBuilderRecursivelyInLoop(EntityManagerInterface $em): QueryBuilder
80+
{
81+
return $this->getQueryBuilderRecursivelyInLoop2($em);
82+
}
83+
84+
private function getQueryBuilderRecursivelyInLoop2(EntityManagerInterface $em): QueryBuilder
85+
{
86+
return $this->getQueryBuilderRecursivelyInLoop($em);
87+
}
88+
7489
private function getQueryBuilder(EntityManagerInterface $em): QueryBuilder
7590
{
7691
return $em->createQueryBuilder()

0 commit comments

Comments
 (0)