Version 1
[yaffs-website] / vendor / psy / psysh / src / Psy / CodeCleaner / CallTimePassByReferencePass.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\Expr\FuncCall as FunctionCall;
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     /**
30      * Validate of use call-time pass-by-reference.
31      *
32      * @throws RuntimeException if the user used call-time pass-by-reference in PHP >= 5.4.0
33      *
34      * @param Node $node
35      */
36     public function enterNode(Node $node)
37     {
38         if (version_compare(PHP_VERSION, '5.4', '<')) {
39             return;
40         }
41
42         if (!$node instanceof FunctionCall && !$node instanceof MethodCall && !$node instanceof StaticCall) {
43             return;
44         }
45
46         foreach ($node->args as $arg) {
47             if ($arg->byRef) {
48                 throw new FatalErrorException('Call-time pass-by-reference has been removed');
49             }
50         }
51     }
52 }