87e685e7986984d8ddd31ffcf4fcae3c0342e855
[yaffs-website] / vendor / psy / psysh / src / CodeCleaner / CallTimePassByReferencePass.php
1 <?php
2
3 /*
4  * This file is part of Psy Shell.
5  *
6  * (c) 2012-2018 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\Expr\FuncCall;
16 use PhpParser\Node\Expr\MethodCall;
17 use PhpParser\Node\Expr\StaticCall;
18 use Psy\Exception\FatalErrorException;
19
20 /**
21  * Validate that the user did not use the call-time pass-by-reference that causes a fatal error.
22  *
23  * As of PHP 5.4.0, call-time pass-by-reference was removed, so using it will raise a fatal error.
24  *
25  * @author Martin HasoĊˆ <martin.hason@gmail.com>
26  */
27 class CallTimePassByReferencePass extends CodeCleanerPass
28 {
29     const EXCEPTION_MESSAGE = 'Call-time pass-by-reference has been removed';
30
31     /**
32      * Validate of use call-time pass-by-reference.
33      *
34      * @throws RuntimeException if the user used call-time pass-by-reference in PHP >= 5.4.0
35      *
36      * @param Node $node
37      */
38     public function enterNode(Node $node)
39     {
40         if (!$node instanceof FuncCall && !$node instanceof MethodCall && !$node instanceof StaticCall) {
41             return;
42         }
43
44         foreach ($node->args as $arg) {
45             if ($arg->byRef) {
46                 throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine());
47             }
48         }
49     }
50 }