4 * This file is part of Psy Shell.
6 * (c) 2012-2017 Justin Hileman
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Psy\CodeCleaner;
14 use PhpParser\Node\Expr;
15 use PhpParser\Node\Expr\Exit_;
16 use PhpParser\Node\Stmt\Return_ as ReturnStmt;
19 * Add an implicit "return" to the last statement, provided it can be returned.
21 class ImplicitReturnPass extends CodeCleanerPass
26 public function beforeTraverse(array $nodes)
30 if ($last instanceof Expr && !($last instanceof Exit_)) {
31 $nodes[count($nodes) - 1] = new ReturnStmt($last, array(
32 'startLine' => $last->getLine(),
33 'endLine' => $last->getLine(),