@@ -113,28 +113,21 @@ private function registerMethodCall(
113
113
$ methodNames = $ this ->getMethodName ($ methodCall , $ scope );
114
114
115
115
if ($ methodCall instanceof New_) {
116
- if ($ methodCall ->class instanceof Expr) {
117
- $ callerType = $ scope ->getType ($ methodCall ->class );
118
- $ possibleDescendantCall = true ;
119
-
120
- } elseif ($ methodCall ->class instanceof Name) {
121
- $ callerType = $ scope ->resolveTypeByName ($ methodCall ->class );
122
- $ possibleDescendantCall = $ methodCall ->class ->toString () === 'static ' ;
123
-
116
+ if ($ methodCall ->class instanceof Expr || $ methodCall ->class instanceof Name) {
117
+ $ callerType = $ scope ->getType ($ methodCall );
124
118
} else {
125
119
return ;
126
120
}
127
121
} else {
128
122
$ callerType = $ scope ->getType ($ methodCall ->var );
129
- $ possibleDescendantCall = true ;
130
123
}
131
124
132
125
foreach ($ methodNames as $ methodName ) {
133
- foreach ($ this ->getDeclaringTypesWithMethod ($ scope , $ callerType , $ methodName , TrinaryLogic::createNo ()) as $ className ) {
126
+ foreach ($ this ->getDeclaringTypesWithMethod ($ methodName , $ callerType , TrinaryLogic::createNo ()) as $ methodRef ) {
134
127
$ this ->registerUsage (
135
128
new ClassMethodUsage (
136
129
$ this ->usageOriginDetector ->detectOrigin ($ scope ),
137
- new ClassMethodRef ( $ className , $ methodName , $ possibleDescendantCall ) ,
130
+ $ methodRef ,
138
131
),
139
132
$ methodCall ,
140
133
$ scope ,
@@ -152,19 +145,16 @@ private function registerStaticCall(
152
145
153
146
if ($ staticCall ->class instanceof Expr) {
154
147
$ callerType = $ scope ->getType ($ staticCall ->class );
155
- $ possibleDescendantCall = true ;
156
-
157
148
} else {
158
- $ callerType = $ scope ->resolveTypeByName ($ staticCall ->class );
159
- $ possibleDescendantCall = $ staticCall ->class ->toString () === 'static ' ;
149
+ $ callerType = $ scope ->resolveTypeByName ($ staticCall ->class ); // broken in PHPStan, the type here is marked as NOT final
160
150
}
161
151
162
152
foreach ($ methodNames as $ methodName ) {
163
- foreach ($ this ->getDeclaringTypesWithMethod ($ scope , $ callerType , $ methodName , TrinaryLogic::createYes ()) as $ className ) {
153
+ foreach ($ this ->getDeclaringTypesWithMethod ($ methodName , $ callerType , TrinaryLogic::createYes ()) as $ methodRef ) {
164
154
$ this ->registerUsage (
165
155
new ClassMethodUsage (
166
156
$ this ->usageOriginDetector ->detectOrigin ($ scope ),
167
- new ClassMethodRef ( $ className , $ methodName , $ possibleDescendantCall ) ,
157
+ $ methodRef ,
168
158
),
169
159
$ staticCall ,
170
160
$ scope ,
@@ -186,14 +176,11 @@ private function registerArrayCallable(
186
176
$ caller = $ typeAndName ->getType ();
187
177
$ methodName = $ typeAndName ->getMethod ();
188
178
189
- // currently always true, see https://github.com/phpstan/phpstan-src/pull/3372
190
- $ possibleDescendantCall = !$ caller ->isClassString ()->yes ();
191
-
192
- foreach ($ this ->getDeclaringTypesWithMethod ($ scope , $ caller , $ methodName , TrinaryLogic::createMaybe ()) as $ className ) {
179
+ foreach ($ this ->getDeclaringTypesWithMethod ($ methodName , $ caller , TrinaryLogic::createMaybe ()) as $ methodRef ) {
193
180
$ this ->registerUsage (
194
181
new ClassMethodUsage (
195
182
$ this ->usageOriginDetector ->detectOrigin ($ scope ),
196
- new ClassMethodRef ( $ className , $ methodName , $ possibleDescendantCall ) ,
183
+ $ methodRef ,
197
184
),
198
185
$ array ,
199
186
$ scope ,
@@ -221,11 +208,11 @@ private function registerClone(Clone_ $node, Scope $scope): void
221
208
$ methodName = '__clone ' ;
222
209
$ callerType = $ scope ->getType ($ node ->expr );
223
210
224
- foreach ($ this ->getDeclaringTypesWithMethod ($ scope , $ callerType , $ methodName , TrinaryLogic::createNo ()) as $ className ) {
211
+ foreach ($ this ->getDeclaringTypesWithMethod ($ methodName , $ callerType , TrinaryLogic::createNo ()) as $ methodRef ) {
225
212
$ this ->registerUsage (
226
213
new ClassMethodUsage (
227
214
$ this ->usageOriginDetector ->detectOrigin ($ scope ),
228
- new ClassMethodRef ( $ className , $ methodName , true ) ,
215
+ $ methodRef ,
229
216
),
230
217
$ node ,
231
218
$ scope ,
@@ -257,12 +244,11 @@ private function getMethodName(CallLike $call, Scope $scope): array
257
244
}
258
245
259
246
/**
260
- * @return list<class-string<object>|null >
247
+ * @return list<ClassMethodRef >
261
248
*/
262
249
private function getDeclaringTypesWithMethod (
263
- Scope $ scope ,
264
- Type $ type ,
265
250
string $ methodName ,
251
+ Type $ type ,
266
252
TrinaryLogic $ isStaticCall
267
253
): array
268
254
{
@@ -273,15 +259,15 @@ private function getDeclaringTypesWithMethod(
273
259
$ result = [];
274
260
275
261
foreach ($ classReflections as $ classReflection ) {
276
- $ result [] = $ classReflection ->getName ();
262
+ $ result [] = new ClassMethodRef ( $ classReflection ->getName (), $ methodName , ! $ classReflection -> isFinal () );
277
263
}
278
264
279
265
if ($ this ->trackMixedAccess ) {
280
266
$ canBeObjectCall = !$ typeNoNull ->isObject ()->no () && !$ isStaticCall ->yes ();
281
267
$ canBeClassStringCall = !$ typeNoNull ->isClassString ()->no () && !$ isStaticCall ->no ();
282
268
283
269
if ($ result === [] && ($ canBeObjectCall || $ canBeClassStringCall )) {
284
- $ result [] = null ; // call over unknown type
270
+ $ result [] = new ClassMethodRef ( null , $ methodName , true ) ; // call over unknown type
285
271
}
286
272
}
287
273
0 commit comments