@@ -131,7 +131,7 @@ private function registerFetch(ClassConstFetch $node, Scope $scope): void
131
131
{
132
132
if ($ node ->class instanceof Expr) {
133
133
$ ownerType = $ scope ->getType ($ node ->class );
134
- $ possibleDescendantFetch = true ;
134
+ $ possibleDescendantFetch = null ;
135
135
} else {
136
136
$ ownerType = $ scope ->resolveTypeByName ($ node ->class );
137
137
$ possibleDescendantFetch = $ node ->class ->toString () === 'static ' ;
@@ -146,11 +146,11 @@ private function registerFetch(ClassConstFetch $node, Scope $scope): void
146
146
continue ; // reserved for class name fetching
147
147
}
148
148
149
- foreach ($ this ->getDeclaringTypesWithConstant ($ ownerType , $ constantName ) as $ className ) {
149
+ foreach ($ this ->getDeclaringTypesWithConstant ($ ownerType , $ constantName, $ possibleDescendantFetch ) as $ constantRef ) {
150
150
$ this ->registerUsage (
151
151
new ClassConstantUsage (
152
152
UsageOrigin::createRegular ($ node , $ scope ),
153
- new ClassConstantRef ( $ className , $ constantName , $ possibleDescendantFetch ) ,
153
+ $ constantRef ,
154
154
),
155
155
$ node ,
156
156
$ scope ,
@@ -160,29 +160,26 @@ private function registerFetch(ClassConstFetch $node, Scope $scope): void
160
160
}
161
161
162
162
/**
163
- * @return list<class-string<object>|null >
163
+ * @return list<ClassConstantRef >
164
164
*/
165
165
private function getDeclaringTypesWithConstant (
166
166
Type $ type ,
167
- string $ constantName
167
+ string $ constantName ,
168
+ ?bool $ isPossibleDescendant
168
169
): array
169
170
{
170
- $ typeNormalized = TypeUtils::toBenevolentUnion ($ type ); // extract possible calls even from Class|int
171
+ $ typeNormalized = TypeUtils::toBenevolentUnion ($ type ); // extract possible fetches even from Class|int
171
172
$ classReflections = $ typeNormalized ->getObjectTypeOrClassStringObjectType ()->getObjectClassReflections ();
172
173
173
174
$ result = [];
174
175
175
176
foreach ($ classReflections as $ classReflection ) {
176
- if ($ classReflection ->hasConstant ($ constantName )) {
177
- $ result [] = $ classReflection ->getConstant ($ constantName )->getDeclaringClass ()->getName ();
178
-
179
- } else { // unknown constant fetch (might be present on children)
180
- $ result [] = $ classReflection ->getName ();
181
- }
177
+ $ possibleDescendant = $ isPossibleDescendant ?? !$ classReflection ->isFinal ();
178
+ $ result [] = new ClassConstantRef ($ classReflection ->getName (), $ constantName , $ possibleDescendant );
182
179
}
183
180
184
181
if ($ result === []) {
185
- $ result [] = null ; // call over unknown type
182
+ $ result [] = new ClassConstantRef ( null , $ constantName , true ) ; // call over unknown type
186
183
}
187
184
188
185
return $ result ;
0 commit comments