@@ -113,17 +113,24 @@ private function registerMethodCall(
113
113
$ methodNames = $ this ->getMethodName ($ methodCall , $ scope );
114
114
115
115
if ($ methodCall instanceof New_) {
116
- if ($ methodCall ->class instanceof Expr || $ methodCall -> class instanceof Name ) {
116
+ if ($ methodCall ->class instanceof Expr) {
117
117
$ callerType = $ scope ->getType ($ methodCall );
118
+ $ possibleDescendantCall = null ;
119
+
120
+ } elseif ($ methodCall ->class instanceof Name) {
121
+ $ callerType = $ scope ->resolveTypeByName ($ methodCall ->class );
122
+ $ possibleDescendantCall = $ methodCall ->class ->toString () === 'static ' ;
123
+
118
124
} else {
119
125
return ;
120
126
}
121
127
} else {
122
128
$ callerType = $ scope ->getType ($ methodCall ->var );
129
+ $ possibleDescendantCall = null ;
123
130
}
124
131
125
132
foreach ($ methodNames as $ methodName ) {
126
- foreach ($ this ->getDeclaringTypesWithMethod ($ methodName , $ callerType , TrinaryLogic::createNo ()) as $ methodRef ) {
133
+ foreach ($ this ->getDeclaringTypesWithMethod ($ methodName , $ callerType , TrinaryLogic::createNo (), $ possibleDescendantCall ) as $ methodRef ) {
127
134
$ this ->registerUsage (
128
135
new ClassMethodUsage (
129
136
$ this ->usageOriginDetector ->detectOrigin ($ scope ),
@@ -145,12 +152,15 @@ private function registerStaticCall(
145
152
146
153
if ($ staticCall ->class instanceof Expr) {
147
154
$ callerType = $ scope ->getType ($ staticCall ->class );
155
+ $ possibleDescendantCall = null ;
156
+
148
157
} else {
149
- $ callerType = $ scope ->resolveTypeByName ($ staticCall ->class ); // broken in PHPStan, the type here is marked as NOT final
158
+ $ callerType = $ scope ->resolveTypeByName ($ staticCall ->class );
159
+ $ possibleDescendantCall = $ staticCall ->class ->toString () === 'static ' ;
150
160
}
151
161
152
162
foreach ($ methodNames as $ methodName ) {
153
- foreach ($ this ->getDeclaringTypesWithMethod ($ methodName , $ callerType , TrinaryLogic::createYes ()) as $ methodRef ) {
163
+ foreach ($ this ->getDeclaringTypesWithMethod ($ methodName , $ callerType , TrinaryLogic::createYes (), $ possibleDescendantCall ) as $ methodRef ) {
154
164
$ this ->registerUsage (
155
165
new ClassMethodUsage (
156
166
$ this ->usageOriginDetector ->detectOrigin ($ scope ),
@@ -249,7 +259,8 @@ private function getMethodName(CallLike $call, Scope $scope): array
249
259
private function getDeclaringTypesWithMethod (
250
260
string $ methodName ,
251
261
Type $ type ,
252
- TrinaryLogic $ isStaticCall
262
+ TrinaryLogic $ isStaticCall ,
263
+ ?bool $ isPossibleDescendant = null
253
264
): array
254
265
{
255
266
$ typeNoNull = TypeCombinator::removeNull ($ type ); // remove null to support nullsafe calls
@@ -259,7 +270,8 @@ private function getDeclaringTypesWithMethod(
259
270
$ result = [];
260
271
261
272
foreach ($ classReflections as $ classReflection ) {
262
- $ result [] = new ClassMethodRef ($ classReflection ->getName (), $ methodName , !$ classReflection ->isFinal ());
273
+ $ possibleDescendant = $ isPossibleDescendant ?? !$ classReflection ->isFinal ();
274
+ $ result [] = new ClassMethodRef ($ classReflection ->getName (), $ methodName , $ possibleDescendant );
263
275
}
264
276
265
277
if ($ this ->trackMixedAccess ) {
0 commit comments