Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 * This file is part of Psy Shell.
|
Chris@0
|
5 *
|
Chris@0
|
6 * (c) 2012-2017 Justin Hileman
|
Chris@0
|
7 *
|
Chris@0
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@0
|
9 * file that was distributed with this source code.
|
Chris@0
|
10 */
|
Chris@0
|
11
|
Chris@0
|
12 namespace Psy\CodeCleaner;
|
Chris@0
|
13
|
Chris@0
|
14 use PhpParser\Node;
|
Chris@0
|
15 use PhpParser\Node\Expr\FuncCall;
|
Chris@0
|
16 use PhpParser\Node\Expr\MethodCall;
|
Chris@0
|
17 use PhpParser\Node\Expr\StaticCall;
|
Chris@0
|
18 use Psy\Exception\FatalErrorException;
|
Chris@0
|
19
|
Chris@0
|
20 /**
|
Chris@0
|
21 * Validate that the user did not use the call-time pass-by-reference that causes a fatal error.
|
Chris@0
|
22 *
|
Chris@0
|
23 * As of PHP 5.4.0, call-time pass-by-reference was removed, so using it will raise a fatal error.
|
Chris@0
|
24 *
|
Chris@0
|
25 * @author Martin HasoĊ <martin.hason@gmail.com>
|
Chris@0
|
26 */
|
Chris@0
|
27 class CallTimePassByReferencePass extends CodeCleanerPass
|
Chris@0
|
28 {
|
Chris@0
|
29 const EXCEPTION_MESSAGE = 'Call-time pass-by-reference has been removed';
|
Chris@0
|
30
|
Chris@0
|
31 /**
|
Chris@0
|
32 * Validate of use call-time pass-by-reference.
|
Chris@0
|
33 *
|
Chris@0
|
34 * @throws RuntimeException if the user used call-time pass-by-reference in PHP >= 5.4.0
|
Chris@0
|
35 *
|
Chris@0
|
36 * @param Node $node
|
Chris@0
|
37 */
|
Chris@0
|
38 public function enterNode(Node $node)
|
Chris@0
|
39 {
|
Chris@0
|
40 if (version_compare(PHP_VERSION, '5.4', '<')) {
|
Chris@0
|
41 return;
|
Chris@0
|
42 }
|
Chris@0
|
43
|
Chris@0
|
44 if (!$node instanceof FuncCall && !$node instanceof MethodCall && !$node instanceof StaticCall) {
|
Chris@0
|
45 return;
|
Chris@0
|
46 }
|
Chris@0
|
47
|
Chris@0
|
48 foreach ($node->args as $arg) {
|
Chris@0
|
49 if ($arg->byRef) {
|
Chris@0
|
50 throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine());
|
Chris@0
|
51 }
|
Chris@0
|
52 }
|
Chris@0
|
53 }
|
Chris@0
|
54 }
|