Version 1
[yaffs-website] / vendor / psy / psysh / src / Psy / CodeCleaner / ExitPass.php
1 <?php
2
3 /*
4  * This file is part of Psy Shell.
5  *
6  * (c) 2012-2017 Justin Hileman
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Psy\CodeCleaner;
13
14 use PhpParser\Node;
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_;
21
22 class ExitPass extends CodeCleanerPass
23 {
24     /**
25      * Converts exit calls to BreakExceptions.
26      *
27      * @param \PhpParser\Node $node
28      */
29     public function leaveNode(Node $node)
30     {
31         if ($node instanceof Exit_) {
32             $args = array(new Arg(new String_('Goodbye.')));
33
34             return new Throw_(new New_(new Name('Psy\Exception\BreakException'), $args));
35         }
36     }
37 }