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;
15 use PhpParser\Node\Arg;
16 use PhpParser\Node\Expr\Exit_;
17 use PhpParser\Node\Expr\New_;
18 use PhpParser\Node\Name;
19 use PhpParser\Node\Scalar\String_;
20 use PhpParser\Node\Stmt\Throw_;
22 class ExitPass extends CodeCleanerPass
25 * Converts exit calls to BreakExceptions.
27 * @param \PhpParser\Node $node
29 public function leaveNode(Node $node)
31 if ($node instanceof Exit_) {
32 $args = array(new Arg(new String_('Goodbye.')));
34 return new Throw_(new New_(new Name('Psy\Exception\BreakException'), $args));