22
22
use PHPStan \Type \TypeTraverser ;
23
23
use PHPStan \Type \UnionType ;
24
24
use function is_array ;
25
+ use function sprintf ;
25
26
26
27
class OtherMethodQueryBuilderParser
27
28
{
@@ -35,7 +36,7 @@ class OtherMethodQueryBuilderParser
35
36
/** @var Container */
36
37
private $ container ;
37
38
38
- /** @var array<string, array<string, list<QueryBuilderType> >> */
39
+ /** @var array<string, list<QueryBuilderType>> */
39
40
private $ cache = [];
40
41
41
42
public function __construct (bool $ descendIntoOtherMethods , Parser $ parser , Container $ container )
@@ -55,17 +56,20 @@ public function findQueryBuilderTypesInCalledMethod(Scope $scope, MethodReflecti
55
56
}
56
57
57
58
$ methodName = $ methodReflection ->getName ();
59
+ $ className = $ methodReflection ->getDeclaringClass ()->getName ();
58
60
$ fileName = $ methodReflection ->getDeclaringClass ()->getFileName ();
59
61
if ($ fileName === null ) {
60
62
return [];
61
63
}
62
64
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 ];
65
69
}
66
70
67
71
$ nodes = $ this ->parser ->parseFile ($ fileName );
68
- $ classNode = $ this ->findClassNode ($ methodReflection -> getDeclaringClass ()-> getName () , $ nodes );
72
+ $ classNode = $ this ->findClassNode ($ className , $ nodes );
69
73
if ($ classNode === null ) {
70
74
return [];
71
75
}
@@ -108,7 +112,7 @@ public function findQueryBuilderTypesInCalledMethod(Scope $scope, MethodReflecti
108
112
});
109
113
});
110
114
111
- $ this ->cache [$ fileName ][ $ methodName ] = $ queryBuilderTypes ;
115
+ $ this ->cache [$ cacheKey ] = $ queryBuilderTypes ;
112
116
113
117
return $ queryBuilderTypes ;
114
118
}
@@ -169,4 +173,9 @@ private function findMethodNode(string $methodName, array $classStatements): ?Cl
169
173
return null ;
170
174
}
171
175
176
+ private function buildCacheKey (string $ fileName , string $ declaringClassName , string $ methodName ): string
177
+ {
178
+ return sprintf ('%s-%s-%s ' , $ fileName , $ declaringClassName , $ methodName );
179
+ }
180
+
172
181
}
0 commit comments