Yaffs site version 1.1
[yaffs-website] / vendor / psy / psysh / src / Psy / CodeCleaner / FunctionReturnInWriteContextPass.php
index fd3430eaa3c8c0ec1c5bf924f6899aea8d8818f7..de2530619f56f32a2e4ba1f3b58b976c62a8908f 100644 (file)
 namespace Psy\CodeCleaner;
 
 use PhpParser\Node;
-use PhpParser\Node\Expr\Array_ as ArrayNode;
-use PhpParser\Node\Expr\Assign as AssignNode;
-use PhpParser\Node\Expr\Empty_ as EmptyNode;
-use PhpParser\Node\Expr\FuncCall as FunctionCall;
-use PhpParser\Node\Expr\Isset_ as IssetNode;
+use PhpParser\Node\Expr\Array_;
+use PhpParser\Node\Expr\Assign;
+use PhpParser\Node\Expr\Empty_;
+use PhpParser\Node\Expr\FuncCall;
+use PhpParser\Node\Expr\Isset_;
 use PhpParser\Node\Expr\MethodCall;
 use PhpParser\Node\Expr\StaticCall;
 use Psy\Exception\FatalErrorException;
@@ -28,6 +28,7 @@ use Psy\Exception\FatalErrorException;
  */
 class FunctionReturnInWriteContextPass extends CodeCleanerPass
 {
+    const PHP55_MESSAGE = 'Cannot use isset() on the result of a function call (you can use "null !== func()" instead)';
     const EXCEPTION_MESSAGE = "Can't use function return value in write context";
 
     private $isPhp55;
@@ -49,34 +50,31 @@ class FunctionReturnInWriteContextPass extends CodeCleanerPass
      */
     public function enterNode(Node $node)
     {
-        if ($node instanceof ArrayNode || $this->isCallNode($node)) {
-            $items = $node instanceof ArrayNode ? $node->items : $node->args;
+        if ($node instanceof Array_ || $this->isCallNode($node)) {
+            $items = $node instanceof Array_ ? $node->items : $node->args;
             foreach ($items as $item) {
                 if ($item->byRef && $this->isCallNode($item->value)) {
-                    throw new FatalErrorException(self::EXCEPTION_MESSAGE);
+                    throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine());
                 }
             }
-        } elseif ($node instanceof IssetNode) {
+        } elseif ($node instanceof Isset_) {
             foreach ($node->vars as $var) {
                 if (!$this->isCallNode($var)) {
                     continue;
                 }
 
-                if ($this->isPhp55) {
-                    throw new FatalErrorException('Cannot use isset() on the result of a function call (you can use "null !== func()" instead)');
-                } else {
-                    throw new FatalErrorException(self::EXCEPTION_MESSAGE);
-                }
+                $msg = $this->isPhp55 ? self::PHP55_MESSAGE : self::EXCEPTION_MESSAGE;
+                throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
             }
-        } elseif ($node instanceof EmptyNode && !$this->isPhp55 && $this->isCallNode($node->expr)) {
-            throw new FatalErrorException(self::EXCEPTION_MESSAGE);
-        } elseif ($node instanceof AssignNode && $this->isCallNode($node->var)) {
-            throw new FatalErrorException(self::EXCEPTION_MESSAGE);
+        } elseif ($node instanceof Empty_ && !$this->isPhp55 && $this->isCallNode($node->expr)) {
+            throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine());
+        } elseif ($node instanceof Assign && $this->isCallNode($node->var)) {
+            throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine());
         }
     }
 
     private function isCallNode(Node $node)
     {
-        return $node instanceof FunctionCall || $node instanceof MethodCall || $node instanceof StaticCall;
+        return $node instanceof FuncCall || $node instanceof MethodCall || $node instanceof StaticCall;
     }
 }