@@ -112,8 +112,7 @@ protected function resolve(Node $node)
112112 try {
113113 ++$ this ->nodeLevel ;
114114
115- $ nodeType = $ node ->getType ();
116- $ methodName = 'resolve ' . str_replace ('_ ' , '' , $ nodeType );
115+ $ methodName = $ this ->getDispatchMethodFor ($ node );
117116 if (method_exists ($ this , $ methodName )) {
118117 $ value = $ this ->$ methodName ($ node );
119118 }
@@ -142,7 +141,7 @@ protected function resolveScalarString(Scalar\String_ $node)
142141 protected function resolveScalarMagicConstMethod ()
143142 {
144143 if ($ this ->context instanceof \ReflectionMethod) {
145- $ fullName = $ this ->context ->getDeclaringClass ()->getName () . ':: ' . $ this ->context ->getShortName ();
144+ $ fullName = $ this ->context ->getDeclaringClass ()->name . ':: ' . $ this ->context ->getShortName ();
146145
147146 return $ fullName ;
148147 }
@@ -175,12 +174,12 @@ protected function resolveScalarMagicConstNamespace()
175174 protected function resolveScalarMagicConstClass ()
176175 {
177176 if ($ this ->context instanceof \ReflectionClass) {
178- return $ this ->context ->getName () ;
177+ return $ this ->context ->name ;
179178 }
180179 if (method_exists ($ this ->context , 'getDeclaringClass ' )) {
181180 $ declaringClass = $ this ->context ->getDeclaringClass ();
182181 if ($ declaringClass instanceof \ReflectionClass) {
183- return $ declaringClass ->getName () ;
182+ return $ declaringClass ->name ;
184183 }
185184 }
186185
@@ -213,7 +212,7 @@ protected function resolveScalarMagicConstLine(MagicConst\Line $node)
213212 protected function resolveScalarMagicConstTrait ()
214213 {
215214 if ($ this ->context instanceof \ReflectionClass && $ this ->context ->isTrait ()) {
216- return $ this ->context ->getName () ;
215+ return $ this ->context ->name ;
217216 }
218217
219218 return '' ;
@@ -224,8 +223,6 @@ protected function resolveExprConstFetch(Expr\ConstFetch $node)
224223 $ constantValue = null ;
225224 $ isResolved = false ;
226225
227- /** @var ReflectionFileNamespace|null $fileNamespace */
228- $ fileNamespace = null ;
229226 $ isFQNConstant = $ node ->name instanceof Node \Name \FullyQualified;
230227 $ constantName = $ node ->name ->toString ();
231228
@@ -256,7 +253,22 @@ protected function resolveExprConstFetch(Expr\ConstFetch $node)
256253
257254 protected function resolveExprClassConstFetch (Expr \ClassConstFetch $ node )
258255 {
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 );
260272 $ constantName = $ node ->name ;
261273
262274 // special handling of ::class constants
@@ -265,7 +277,7 @@ protected function resolveExprClassConstFetch(Expr\ClassConstFetch $node)
265277 }
266278
267279 $ this ->isConstant = true ;
268- $ this ->constantName = (string )$ node -> class . ':: ' . $ constantName ;
280+ $ this ->constantName = (string )$ classToReflect . ':: ' . $ constantName ;
269281
270282 return $ refClass ->getConstant ($ constantName );
271283 }
@@ -430,6 +442,12 @@ protected function resolveExprBinaryOpLogicalXor(Expr\BinaryOp\LogicalXor $node)
430442 return $ this ->resolve ($ node ->left ) xor $ this ->resolve ($ node ->right );
431443 }
432444
445+ private function getDispatchMethodFor (Node $ node )
446+ {
447+ $ nodeType = $ node ->getType ();
448+ return 'resolve ' . str_replace ('_ ' , '' , $ nodeType );
449+ }
450+
433451 /**
434452 * Utility method to fetch reflection class instance by name
435453 *
0 commit comments