-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathUseSafeCallablesRule.php
More file actions
44 lines (37 loc) · 1.1 KB
/
UseSafeCallablesRule.php
File metadata and controls
44 lines (37 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace TheCodingMachine\Safe\PHPStan\Rules;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Node\FunctionCallableNode;
use TheCodingMachine\Safe\PHPStan\Rules\Error\SafeFunctionRuleError;
use TheCodingMachine\Safe\PHPStan\Utils\FunctionListLoader;
/**
* This rule checks that no "unsafe" functions are used in code.
*
* @implements Rule<FunctionCallableNode>
*/
class UseSafeCallablesRule implements Rule
{
/**
* @see JSON_THROW_ON_ERROR
*/
const JSON_THROW_ON_ERROR = 4194304;
public function getNodeType(): string
{
return FunctionCallableNode::class;
}
public function processNode(Node $node, Scope $scope): array
{
$nodeName = $node->getName();
if (!$nodeName instanceof Node\Name) {
return [];
}
$functionName = $nodeName->toString();
$unsafeFunctions = FunctionListLoader::getFunctionList();
if (isset($unsafeFunctions[$functionName])) {
return [new SafeFunctionRuleError($nodeName, $node->getStartLine())];
}
return [];
}
}