@@ -112,8 +112,7 @@ protected function resolve(Node $node)
112
112
try {
113
113
++$ this ->nodeLevel ;
114
114
115
- $ nodeType = $ node ->getType ();
116
- $ methodName = 'resolve ' . str_replace ('_ ' , '' , $ nodeType );
115
+ $ methodName = $ this ->getDispatchMethodFor ($ node );
117
116
if (method_exists ($ this , $ methodName )) {
118
117
$ value = $ this ->$ methodName ($ node );
119
118
}
@@ -142,7 +141,7 @@ protected function resolveScalarString(Scalar\String_ $node)
142
141
protected function resolveScalarMagicConstMethod ()
143
142
{
144
143
if ($ this ->context instanceof \ReflectionMethod) {
145
- $ fullName = $ this ->context ->getDeclaringClass ()->getName () . ':: ' . $ this ->context ->getShortName ();
144
+ $ fullName = $ this ->context ->getDeclaringClass ()->name . ':: ' . $ this ->context ->getShortName ();
146
145
147
146
return $ fullName ;
148
147
}
@@ -175,12 +174,12 @@ protected function resolveScalarMagicConstNamespace()
175
174
protected function resolveScalarMagicConstClass ()
176
175
{
177
176
if ($ this ->context instanceof \ReflectionClass) {
178
- return $ this ->context ->getName () ;
177
+ return $ this ->context ->name ;
179
178
}
180
179
if (method_exists ($ this ->context , 'getDeclaringClass ' )) {
181
180
$ declaringClass = $ this ->context ->getDeclaringClass ();
182
181
if ($ declaringClass instanceof \ReflectionClass) {
183
- return $ declaringClass ->getName () ;
182
+ return $ declaringClass ->name ;
184
183
}
185
184
}
186
185
@@ -213,7 +212,7 @@ protected function resolveScalarMagicConstLine(MagicConst\Line $node)
213
212
protected function resolveScalarMagicConstTrait ()
214
213
{
215
214
if ($ this ->context instanceof \ReflectionClass && $ this ->context ->isTrait ()) {
216
- return $ this ->context ->getName () ;
215
+ return $ this ->context ->name ;
217
216
}
218
217
219
218
return '' ;
@@ -224,8 +223,6 @@ protected function resolveExprConstFetch(Expr\ConstFetch $node)
224
223
$ constantValue = null ;
225
224
$ isResolved = false ;
226
225
227
- /** @var ReflectionFileNamespace|null $fileNamespace */
228
- $ fileNamespace = null ;
229
226
$ isFQNConstant = $ node ->name instanceof Node \Name \FullyQualified;
230
227
$ constantName = $ node ->name ->toString ();
231
228
@@ -256,7 +253,22 @@ protected function resolveExprConstFetch(Expr\ConstFetch $node)
256
253
257
254
protected function resolveExprClassConstFetch (Expr \ClassConstFetch $ node )
258
255
{
259
- $ refClass = $ this ->fetchReflectionClass ($ node ->class );
256
+ $ classToReflect = $ node ->class ;
257
+ if (!($ classToReflect instanceof Node \Name)) {
258
+ $ classToReflect = $ this ->resolve ($ classToReflect ) ?: $ classToReflect ;
259
+ if (!is_string ($ classToReflect )) {
260
+ $ reason = 'Unable ' ;
261
+ if ($ classToReflect instanceof Expr) {
262
+ $ methodName = $ this ->getDispatchMethodFor ($ classToReflect );
263
+ $ reason = "Method " . __CLASS__ . ":: {$ methodName }() not found trying " ;
264
+ }
265
+ throw new ReflectionException ("$ reason to resolve class constant. " );
266
+ }
267
+ // Strings evaluated as class names are always treated as fully
268
+ // qualified.
269
+ $ classToReflect = new Node \Name \FullyQualified (ltrim ($ classToReflect , '\\' ));
270
+ }
271
+ $ refClass = $ this ->fetchReflectionClass ($ classToReflect );
260
272
$ constantName = $ node ->name ;
261
273
262
274
// special handling of ::class constants
@@ -265,7 +277,7 @@ protected function resolveExprClassConstFetch(Expr\ClassConstFetch $node)
265
277
}
266
278
267
279
$ this ->isConstant = true ;
268
- $ this ->constantName = (string )$ node -> class . ':: ' . $ constantName ;
280
+ $ this ->constantName = (string )$ classToReflect . ':: ' . $ constantName ;
269
281
270
282
return $ refClass ->getConstant ($ constantName );
271
283
}
@@ -430,6 +442,12 @@ protected function resolveExprBinaryOpLogicalXor(Expr\BinaryOp\LogicalXor $node)
430
442
return $ this ->resolve ($ node ->left ) xor $ this ->resolve ($ node ->right );
431
443
}
432
444
445
+ private function getDispatchMethodFor (Node $ node )
446
+ {
447
+ $ nodeType = $ node ->getType ();
448
+ return 'resolve ' . str_replace ('_ ' , '' , $ nodeType );
449
+ }
450
+
433
451
/**
434
452
* Utility method to fetch reflection class instance by name
435
453
*
0 commit comments