| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of Psy Shell.
|
|
|
5 |
*
|
|
|
6 |
* (c) 2012-2022 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 PhpParser\Node\VariadicPlaceholder;
|
|
|
19 |
use Psy\Exception\FatalErrorException;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Validate that the user did not use the call-time pass-by-reference that causes a fatal error.
|
|
|
23 |
*
|
|
|
24 |
* As of PHP 5.4.0, call-time pass-by-reference was removed, so using it will raise a fatal error.
|
|
|
25 |
*
|
|
|
26 |
* @author Martin Hasoň <martin.hason@gmail.com>
|
|
|
27 |
*/
|
|
|
28 |
class CallTimePassByReferencePass extends CodeCleanerPass
|
|
|
29 |
{
|
|
|
30 |
const EXCEPTION_MESSAGE = 'Call-time pass-by-reference has been removed';
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Validate of use call-time pass-by-reference.
|
|
|
34 |
*
|
|
|
35 |
* @throws FatalErrorException if the user used call-time pass-by-reference
|
|
|
36 |
*
|
|
|
37 |
* @param Node $node
|
|
|
38 |
*
|
|
|
39 |
* @return int|Node|null Replacement node (or special return value)
|
|
|
40 |
*/
|
|
|
41 |
public function enterNode(Node $node)
|
|
|
42 |
{
|
|
|
43 |
if (!$node instanceof FuncCall && !$node instanceof MethodCall && !$node instanceof StaticCall) {
|
|
|
44 |
return;
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
foreach ($node->args as $arg) {
|
|
|
48 |
if ($arg instanceof VariadicPlaceholder) {
|
|
|
49 |
continue;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
if ($arg->byRef) {
|
|
|
53 |
throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, \E_ERROR, null, $node->getLine());
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
}
|