3
3
namespace PHPStan \Type \Doctrine \QueryBuilder ;
4
4
5
5
use PhpParser \Node ;
6
- use PhpParser \Node \Expr \MethodCall ;
7
- use PhpParser \Node \Identifier ;
8
6
use PhpParser \Node \Stmt ;
9
7
use PhpParser \Node \Stmt \Class_ ;
10
8
use PhpParser \Node \Stmt \ClassMethod ;
17
15
use PHPStan \Analyser \ScopeFactory ;
18
16
use PHPStan \DependencyInjection \Container ;
19
17
use PHPStan \Parser \Parser ;
20
- use PHPStan \Reflection \ReflectionProvider ;
18
+ use PHPStan \Reflection \MethodReflection ;
21
19
use PHPStan \Type \Generic \TemplateTypeMap ;
22
20
use PHPStan \Type \IntersectionType ;
23
21
use PHPStan \Type \Type ;
24
22
use PHPStan \Type \TypeTraverser ;
25
23
use PHPStan \Type \UnionType ;
26
- use function count ;
27
24
use function is_array ;
28
25
29
26
class OtherMethodQueryBuilderParser
@@ -32,61 +29,28 @@ class OtherMethodQueryBuilderParser
32
29
/** @var bool */
33
30
private $ descendIntoOtherMethods ;
34
31
35
- /** @var ReflectionProvider */
36
- private $ reflectionProvider ;
37
-
38
32
/** @var Parser */
39
33
private $ parser ;
40
34
41
35
/** @var Container */
42
36
private $ container ;
43
37
44
- public function __construct (bool $ descendIntoOtherMethods , ReflectionProvider $ reflectionProvider , Parser $ parser , Container $ container )
38
+ public function __construct (bool $ descendIntoOtherMethods , Parser $ parser , Container $ container )
45
39
{
46
40
$ this ->descendIntoOtherMethods = $ descendIntoOtherMethods ;
47
- $ this ->reflectionProvider = $ reflectionProvider ;
48
41
$ this ->parser = $ parser ;
49
42
$ this ->container = $ container ;
50
43
}
51
44
52
45
/**
53
- * @return QueryBuilderType[]
46
+ * @return list< QueryBuilderType>
54
47
*/
55
- public function getQueryBuilderTypes (Scope $ scope , MethodCall $ methodCall ): array
48
+ public function findQueryBuilderTypesInCalledMethod (Scope $ scope , MethodReflection $ methodReflection ): array
56
49
{
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 ) {
86
51
return [];
87
52
}
88
53
89
- $ methodReflection = $ classReflection ->getNativeMethod ($ methodName );
90
54
$ fileName = $ methodReflection ->getDeclaringClass ()->getFileName ();
91
55
if ($ fileName === null ) {
92
56
return [];
0 commit comments