Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / psy / psysh / src / CodeCleaner / ImplicitReturnPass.php
similarity index 74%
rename from vendor/psy/psysh/src/Psy/CodeCleaner/ImplicitReturnPass.php
rename to vendor/psy/psysh/src/CodeCleaner/ImplicitReturnPass.php
index c738bdc12ede9d291575afc9472a6dd40c7811d8..82bb21d8b42b63989589f291c4c96ee85171677d 100644 (file)
@@ -3,7 +3,7 @@
 /*
  * This file is part of Psy Shell.
  *
- * (c) 2012-2017 Justin Hileman
+ * (c) 2012-2018 Justin Hileman
  *
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
 
 namespace Psy\CodeCleaner;
 
+use PhpParser\Node;
 use PhpParser\Node\Expr;
 use PhpParser\Node\Expr\Exit_;
 use PhpParser\Node\Expr\New_;
 use PhpParser\Node\Name\FullyQualified as FullyQualifiedName;
 use PhpParser\Node\Stmt;
 use PhpParser\Node\Stmt\Break_;
+use PhpParser\Node\Stmt\Expression;
 use PhpParser\Node\Stmt\If_;
 use PhpParser\Node\Stmt\Namespace_;
 use PhpParser\Node\Stmt\Return_;
@@ -46,7 +48,7 @@ class ImplicitReturnPass extends CodeCleanerPass
     {
         // If nodes is empty, it can't have a return value.
         if (empty($nodes)) {
-            return array(new Return_(new New_(new FullyQualifiedName('Psy\CodeCleaner\NoReturnValue'))));
+            return [new Return_(new New_(new FullyQualifiedName('Psy\CodeCleaner\NoReturnValue')))];
         }
 
         $last = end($nodes);
@@ -75,10 +77,16 @@ class ImplicitReturnPass extends CodeCleanerPass
                 }
             }
         } elseif ($last instanceof Expr && !($last instanceof Exit_)) {
-            $nodes[count($nodes) - 1] = new Return_($last, array(
+            $nodes[count($nodes) - 1] = new Return_($last, [
                 'startLine' => $last->getLine(),
                 'endLine'   => $last->getLine(),
-            ));
+            ]);
+        } elseif ($last instanceof Expression && !($last->expr instanceof Exit_)) {
+            // For PHP Parser 4.x
+            $nodes[count($nodes) - 1] = new Return_($last->expr, [
+                'startLine' => $last->getLine(),
+                'endLine'   => $last->getLine(),
+            ]);
         } elseif ($last instanceof Namespace_) {
             $last->stmts = $this->addImplicitReturn($last->stmts);
         }
@@ -93,10 +101,28 @@ class ImplicitReturnPass extends CodeCleanerPass
         // We're not adding a fallback return after namespace statements,
         // because code outside namespace statements doesn't really work, and
         // there's already an implicit return in the namespace statement anyway.
-        if ($last instanceof Stmt && !$last instanceof Return_ && !$last instanceof Namespace_) {
+        if (self::isNonExpressionStmt($last)) {
             $nodes[] = new Return_(new New_(new FullyQualifiedName('Psy\CodeCleaner\NoReturnValue')));
         }
 
         return $nodes;
     }
+
+    /**
+     * Check whether a given node is a non-expression statement.
+     *
+     * As of PHP Parser 4.x, Expressions are now instances of Stmt as well, so
+     * we'll exclude them here.
+     *
+     * @param Node $node
+     *
+     * @return bool
+     */
+    private static function isNonExpressionStmt(Node $node)
+    {
+        return $node instanceof Stmt &&
+            !$node instanceof Expression &&
+            !$node instanceof Return_ &&
+            !$node instanceof Namespace_;
+    }
 }