12
12
use PhpParser \Node \Identifier ;
13
13
use PHPStan \Analyser \Scope ;
14
14
use PHPStan \Reflection \MethodReflection ;
15
- use PHPStan \Reflection \ParametersAcceptorSelector ;
16
15
use PHPStan \Rules \Doctrine \ORM \DynamicQueryBuilderArgumentException ;
17
16
use PHPStan \Type \Doctrine \ArgumentsProcessor ;
18
17
use PHPStan \Type \Doctrine \DescriptorRegistry ;
@@ -93,26 +92,22 @@ public function getTypeFromMethodCall(
93
92
MethodReflection $ methodReflection ,
94
93
MethodCall $ methodCall ,
95
94
Scope $ scope
96
- ): Type
95
+ ): ? Type
97
96
{
98
97
$ calledOnType = $ scope ->getType ($ methodCall ->var );
99
- $ defaultReturnType = ParametersAcceptorSelector::selectFromArgs (
100
- $ scope ,
101
- $ methodCall ->getArgs (),
102
- $ methodReflection ->getVariants ()
103
- )->getReturnType ();
98
+
104
99
$ queryBuilderTypes = DoctrineTypeUtils::getQueryBuilderTypes ($ calledOnType );
105
100
if (count ($ queryBuilderTypes ) === 0 ) {
106
- return $ defaultReturnType ;
101
+ return null ;
107
102
}
108
103
109
104
$ objectManager = $ this ->objectMetadataResolver ->getObjectManager ();
110
105
if ($ objectManager === null ) {
111
- return $ defaultReturnType ;
106
+ return null ;
112
107
}
113
108
$ entityManagerInterface = 'Doctrine\ORM\EntityManagerInterface ' ;
114
109
if (!$ objectManager instanceof $ entityManagerInterface ) {
115
- return $ defaultReturnType ;
110
+ return null ;
116
111
}
117
112
118
113
/** @var EntityManagerInterface $objectManager */
@@ -150,7 +145,7 @@ public function getTypeFromMethodCall(
150
145
try {
151
146
$ args = $ this ->argumentsProcessor ->processArgs ($ scope , $ methodName , array_slice ($ calledMethodCall ->getArgs (), 0 , 1 ));
152
147
} catch (DynamicQueryBuilderArgumentException $ e ) {
153
- return $ defaultReturnType ;
148
+ return null ;
154
149
}
155
150
if (count ($ args ) === 1 ) {
156
151
$ queryBuilder ->set ($ args [0 ], $ args [0 ]);
@@ -168,13 +163,13 @@ public function getTypeFromMethodCall(
168
163
if (in_array ($ lowerMethodName , self ::METHODS_NOT_AFFECTING_RESULT_TYPE , true )) {
169
164
continue ;
170
165
}
171
- return $ defaultReturnType ;
166
+ return null ;
172
167
}
173
168
174
169
try {
175
170
$ queryBuilder ->{$ methodName }(...$ args );
176
171
} catch (Throwable $ e ) {
177
- return $ defaultReturnType ;
172
+ return null ;
178
173
}
179
174
}
180
175
0 commit comments