comparison vendor/psy/psysh/src/Psy/CodeCleaner/CallTimePassByReferencePass.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
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;
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 (version_compare(PHP_VERSION, '5.4', '<')) {
41 return;
42 }
43
44 if (!$node instanceof FuncCall && !$node instanceof MethodCall && !$node instanceof StaticCall) {
45 return;
46 }
47
48 foreach ($node->args as $arg) {
49 if ($arg->byRef) {
50 throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine());
51 }
52 }
53 }
54 }