@@ -143,13 +143,13 @@ protected function evaluate(Expr $expr) {
143143 return $ this ->evaluateConstFetch ($ expr );
144144 }
145145
146- if ($ expr instanceof Expr \ClassConstFetch) {
147- return $ this ->evaluateClassConstFetch ($ expr );
148- }
146+ if ($ expr instanceof Expr \ClassConstFetch) {
147+ return $ this ->evaluateClassConstFetch ($ expr );
148+ }
149149
150- if ($ expr instanceof Expr \Cast) {
151- return $ this ->evaluateCast ($ expr );
152- }
150+ if ($ expr instanceof Expr \Cast) {
151+ return $ this ->evaluateCast ($ expr );
152+ }
153153
154154 return ($ this ->fallbackEvaluator )($ expr );
155155 }
@@ -231,76 +231,79 @@ private function evaluateBinaryOp(Expr\BinaryOp $expr) {
231231
232232 /** @return mixed */
233233 private function evaluateConstFetch (Expr \ConstFetch $ expr ) {
234- try {
235- $ name = $ expr ->name ->name ;
236-
237- if (defined ($ name )) {
238- return constant ($ name );
239- }
240- } catch (\Throwable $ t ) {}
234+ try {
235+ $ name = $ expr ->name ->name ;
236+
237+ if (defined ($ name )) {
238+ return constant ($ name );
239+ }
240+ } catch (\Throwable $ t ) {
241+ }
241242
242243 return ($ this ->fallbackEvaluator )($ expr );
243244 }
244245
245- /** @return mixed */
246- private function evaluateClassConstFetch (Expr \ClassConstFetch $ expr ) {
247- try {
248- $ classname = $ expr ->class ->name ;
249- $ property = $ expr ->name ->name ;
250-
251- if ('class ' === $ property ) {
252- return $ classname ;
253- }
254-
255- if (class_exists ($ classname )) {
256- $ class = new \ReflectionClass ($ classname );
257- if (array_key_exists ($ property , $ class ->getConstants ())) {
258- $ oReflectionConstant = $ class ->getReflectionConstant ($ property );
259- if ($ oReflectionConstant ->isPublic ()) {
260- return $ class ->getConstant ($ property );
261- }
262- }
263- }
264- } catch (\Throwable $ t ) {}
265-
266- return ($ this ->fallbackEvaluator )($ expr );
267- }
268-
269- /** @return mixed */
270- private function evaluateCast (Expr \Cast $ expr ) {
271- try {
272- $ subexpr = $ this ->evaluate ($ expr ->expr );
273- $ type = get_class ($ expr );
274- switch ($ type ) {
275- case Expr \Cast \Array_::class:
276- return (array ) $ subexpr ;
277-
278- case Expr \Cast \Bool_::class:
279- return (bool ) $ subexpr ;
280-
281- case Expr \Cast \Double::class:
282- switch ($ expr ->getAttribute ("kind " )) {
283- case Expr \Cast \Double::KIND_DOUBLE :
284- return (double ) $ subexpr ;
285-
286- case Expr \Cast \Double::KIND_FLOAT :
287- case Expr \Cast \Double::KIND_REAL :
288- return (float ) $ subexpr ;
289- }
290-
291- break ;
292-
293- case Expr \Cast \Int_::class:
294- return (int ) $ subexpr ;
295-
296- case Expr \Cast \Object_::class:
297- return (object ) $ subexpr ;
298-
299- case Expr \Cast \String_::class:
300- return (string ) $ subexpr ;
301- }
302- } catch (\Throwable $ t ) {}
303-
304- return ($ this ->fallbackEvaluator )($ expr );
305- }
246+ /** @return mixed */
247+ private function evaluateClassConstFetch (Expr \ClassConstFetch $ expr ) {
248+ try {
249+ $ classname = $ expr ->class ->name ;
250+ $ property = $ expr ->name ->name ;
251+
252+ if ('class ' === $ property ) {
253+ return $ classname ;
254+ }
255+
256+ if (class_exists ($ classname )) {
257+ $ class = new \ReflectionClass ($ classname );
258+ if (array_key_exists ($ property , $ class ->getConstants ())) {
259+ $ oReflectionConstant = $ class ->getReflectionConstant ($ property );
260+ if ($ oReflectionConstant ->isPublic ()) {
261+ return $ class ->getConstant ($ property );
262+ }
263+ }
264+ }
265+ } catch (\Throwable $ t ) {
266+ }
267+
268+ return ($ this ->fallbackEvaluator )($ expr );
269+ }
270+
271+ /** @return mixed */
272+ private function evaluateCast (Expr \Cast $ expr ) {
273+ try {
274+ $ subexpr = $ this ->evaluate ($ expr ->expr );
275+ $ type = get_class ($ expr );
276+ switch ($ type ) {
277+ case Expr \Cast \Array_::class:
278+ return (array ) $ subexpr ;
279+
280+ case Expr \Cast \Bool_::class:
281+ return (bool ) $ subexpr ;
282+
283+ case Expr \Cast \Double::class:
284+ switch ($ expr ->getAttribute ("kind " )) {
285+ case Expr \Cast \Double::KIND_DOUBLE :
286+ return (float ) $ subexpr ;
287+
288+ case Expr \Cast \Double::KIND_FLOAT :
289+ case Expr \Cast \Double::KIND_REAL :
290+ return (float ) $ subexpr ;
291+ }
292+
293+ break ;
294+
295+ case Expr \Cast \Int_::class:
296+ return (int ) $ subexpr ;
297+
298+ case Expr \Cast \Object_::class:
299+ return (object ) $ subexpr ;
300+
301+ case Expr \Cast \String_::class:
302+ return (string ) $ subexpr ;
303+ }
304+ } catch (\Throwable $ t ) {
305+ }
306+
307+ return ($ this ->fallbackEvaluator )($ expr );
308+ }
306309}
0 commit comments