1 | <?php |
||
18 | class ForbiddenFunctionsSniff extends BaseSniff |
||
19 | { |
||
20 | use SuppressingTrait; |
||
21 | |||
22 | /** |
||
23 | * If true, an error will be thrown; otherwise a warning. |
||
24 | * |
||
25 | * @var boolean |
||
26 | */ |
||
27 | public $error = false; |
||
28 | |||
29 | /** |
||
30 | * The used file. |
||
31 | * |
||
32 | * @var FileDecorator|void |
||
33 | */ |
||
34 | protected $file; |
||
35 | |||
36 | /** |
||
37 | * A list of forbidden functions with their alternatives. |
||
38 | * |
||
39 | * The value is NULL if no alternative exists. IE, the function should just not be used. |
||
40 | * |
||
41 | * @var array<string, string|null> |
||
42 | */ |
||
43 | public $forbiddenFunctions = [ |
||
44 | 'eval' => null, |
||
45 | 'die' => 'exit', |
||
46 | 'sizeof' => 'count', |
||
47 | 'delete' => 'unset', |
||
48 | ]; |
||
49 | |||
50 | /** |
||
51 | * Position of the listened token. |
||
52 | * |
||
53 | * @var int|void |
||
54 | */ |
||
55 | protected $stackPos; |
||
56 | |||
57 | /** |
||
58 | * Type-safe getter for the file. |
||
59 | * |
||
60 | * @return FileDecorator |
||
61 | */ |
||
62 | protected function getFile(): FileDecorator |
||
66 | |||
67 | /** |
||
68 | * Type-safe getter for the stack position. |
||
69 | * |
||
70 | * @return int |
||
71 | */ |
||
72 | protected function getStackPos(): int |
||
76 | |||
77 | /** |
||
78 | * Processes this test, when one of its tokens is encountered. |
||
79 | * |
||
80 | * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint |
||
81 | * |
||
82 | * @param File $phpcsFile The file being scanned. |
||
83 | * @param int $stackPtr The position of the current token in the stack passed in $tokens. |
||
84 | * |
||
85 | * @return void |
||
86 | */ |
||
87 | public function process(File $phpcsFile, $stackPtr): void |
||
97 | } |
||
98 |