33namespace PHPStan \Type \Doctrine \QueryBuilder ;
44
55use PhpParser \Node ;
6- use PhpParser \Node \Expr \MethodCall ;
7- use PhpParser \Node \Identifier ;
86use PhpParser \Node \Stmt ;
97use PhpParser \Node \Stmt \Class_ ;
108use PhpParser \Node \Stmt \ClassMethod ;
1715use PHPStan \Analyser \ScopeFactory ;
1816use PHPStan \DependencyInjection \Container ;
1917use PHPStan \Parser \Parser ;
20- use PHPStan \Reflection \ReflectionProvider ;
18+ use PHPStan \Reflection \MethodReflection ;
2119use PHPStan \Type \Generic \TemplateTypeMap ;
2220use PHPStan \Type \IntersectionType ;
2321use PHPStan \Type \Type ;
2422use PHPStan \Type \TypeTraverser ;
2523use PHPStan \Type \UnionType ;
26- use function count ;
2724use function is_array ;
2825
2926class OtherMethodQueryBuilderParser
@@ -32,61 +29,28 @@ class OtherMethodQueryBuilderParser
3229 /** @var bool */
3330 private $ descendIntoOtherMethods ;
3431
35- /** @var ReflectionProvider */
36- private $ reflectionProvider ;
37-
3832 /** @var Parser */
3933 private $ parser ;
4034
4135 /** @var Container */
4236 private $ container ;
4337
44- public function __construct (bool $ descendIntoOtherMethods , ReflectionProvider $ reflectionProvider , Parser $ parser , Container $ container )
38+ public function __construct (bool $ descendIntoOtherMethods , Parser $ parser , Container $ container )
4539 {
4640 $ this ->descendIntoOtherMethods = $ descendIntoOtherMethods ;
47- $ this ->reflectionProvider = $ reflectionProvider ;
4841 $ this ->parser = $ parser ;
4942 $ this ->container = $ container ;
5043 }
5144
5245 /**
53- * @return QueryBuilderType[]
46+ * @return list< QueryBuilderType>
5447 */
55- public function getQueryBuilderTypes (Scope $ scope , MethodCall $ methodCall ): array
48+ public function findQueryBuilderTypesInCalledMethod (Scope $ scope , MethodReflection $ methodReflection ): array
5649 {
57- if (!$ this ->descendIntoOtherMethods || !$ methodCall ->var instanceof MethodCall) {
58- return [];
59- }
60-
61- return $ this ->findQueryBuilderTypesInCalledMethod ($ scope , $ methodCall ->var );
62- }
63- /**
64- * @return QueryBuilderType[]
65- */
66- private function findQueryBuilderTypesInCalledMethod (Scope $ scope , MethodCall $ methodCall ): array
67- {
68- $ methodCalledOnType = $ scope ->getType ($ methodCall ->var );
69- if (!$ methodCall ->name instanceof Identifier) {
70- return [];
71- }
72-
73- $ methodCalledOnTypeClassNames = $ methodCalledOnType ->getObjectClassNames ();
74-
75- if (count ($ methodCalledOnTypeClassNames ) !== 1 ) {
76- return [];
77- }
78-
79- if (!$ this ->reflectionProvider ->hasClass ($ methodCalledOnTypeClassNames [0 ])) {
80- return [];
81- }
82-
83- $ classReflection = $ this ->reflectionProvider ->getClass ($ methodCalledOnTypeClassNames [0 ]);
84- $ methodName = $ methodCall ->name ->toString ();
85- if (!$ classReflection ->hasNativeMethod ($ methodName )) {
50+ if (!$ this ->descendIntoOtherMethods ) {
8651 return [];
8752 }
8853
89- $ methodReflection = $ classReflection ->getNativeMethod ($ methodName );
9054 $ fileName = $ methodReflection ->getDeclaringClass ()->getFileName ();
9155 if ($ fileName === null ) {
9256 return [];
0 commit comments