|
1 | 1 | <?php
|
2 | 2 |
|
3 |
| - |
4 | 3 | namespace TheCodingMachine\Safe\PHPStan\Rules;
|
5 | 4 |
|
6 | 5 | use PhpParser\Node;
|
@@ -31,41 +30,40 @@ public function getNodeType(): string
|
31 | 30 |
|
32 | 31 | public function processNode(Node $node, Scope $scope): array
|
33 | 32 | {
|
34 |
| - if (!$node->name instanceof Node\Name) { |
| 33 | + $name = $node->name; |
| 34 | + if (!$name instanceof Node\Name) { |
35 | 35 | return [];
|
36 | 36 | }
|
37 |
| - $functionName = $node->name->toString(); |
| 37 | + $functionName = $name->toString(); |
38 | 38 | $unsafeFunctions = FunctionListLoader::getFunctionList();
|
39 | 39 |
|
40 | 40 | if (isset($unsafeFunctions[$functionName])) {
|
41 |
| - if (! $node->isFirstClassCallable()) { |
42 |
| - if ($functionName === "json_decode" || $functionName === "json_encode") { |
43 |
| - foreach ($node->args as $arg) { |
44 |
| - if ($arg instanceof Node\Arg && |
45 |
| - $arg->name instanceof Node\Identifier && |
46 |
| - $arg->name->toLowerString() === "flags" |
47 |
| - ) { |
48 |
| - if ($this->argValueIncludeJSONTHROWONERROR($arg)) { |
49 |
| - return []; |
50 |
| - } |
| 41 | + if ($functionName === "json_decode" || $functionName === "json_encode") { |
| 42 | + foreach ($node->args as $arg) { |
| 43 | + if ($arg instanceof Node\Arg && |
| 44 | + $arg->name instanceof Node\Identifier && |
| 45 | + $arg->name->toLowerString() === "flags" |
| 46 | + ) { |
| 47 | + if ($this->argValueIncludeJSONTHROWONERROR($arg)) { |
| 48 | + return []; |
51 | 49 | }
|
52 | 50 | }
|
53 | 51 | }
|
| 52 | + } |
54 | 53 |
|
55 |
| - if ($functionName === "json_decode" |
56 |
| - && $this->argValueIncludeJSONTHROWONERROR($node->getArgs()[3] ?? null) |
57 |
| - ) { |
58 |
| - return []; |
59 |
| - } |
| 54 | + if ($functionName === "json_decode" |
| 55 | + && $this->argValueIncludeJSONTHROWONERROR($node->getArgs()[3] ?? null) |
| 56 | + ) { |
| 57 | + return []; |
| 58 | + } |
60 | 59 |
|
61 |
| - if ($functionName === "json_encode" |
62 |
| - && $this->argValueIncludeJSONTHROWONERROR($node->getArgs()[1] ?? null) |
63 |
| - ) { |
64 |
| - return []; |
65 |
| - } |
| 60 | + if ($functionName === "json_encode" |
| 61 | + && $this->argValueIncludeJSONTHROWONERROR($node->getArgs()[1] ?? null) |
| 62 | + ) { |
| 63 | + return []; |
66 | 64 | }
|
67 | 65 |
|
68 |
| - return [new SafeFunctionRuleError($node->name, $node->getStartLine())]; |
| 66 | + return [new SafeFunctionRuleError($name, $node->getStartLine())]; |
69 | 67 | }
|
70 | 68 |
|
71 | 69 | return [];
|
|
0 commit comments