1 | <?php |
||
19 | abstract class AbstractSniff implements Sniff |
||
20 | { |
||
21 | /** |
||
22 | * The used file. |
||
23 | * |
||
24 | * @var File|void |
||
25 | */ |
||
26 | private $file; |
||
27 | |||
28 | /** |
||
29 | * Position of the listened token. |
||
30 | * |
||
31 | * @var int|void |
||
32 | */ |
||
33 | private $stackPos; |
||
34 | |||
35 | /** |
||
36 | * The used suppresshelper. |
||
37 | * |
||
38 | * @var SuppressHelper |
||
39 | */ |
||
40 | private $suppressHelper = null; |
||
41 | |||
42 | /** |
||
43 | * The used token. |
||
44 | * |
||
45 | * @var array|void |
||
46 | */ |
||
47 | private $token; |
||
48 | |||
49 | /** |
||
50 | * All tokens of the class. |
||
51 | * |
||
52 | * @var array|void The tokens of the class. |
||
53 | */ |
||
54 | protected $tokens; |
||
55 | |||
56 | /** |
||
57 | * Returns true if the requirements for this sniff are met. |
||
58 | * |
||
59 | * @return bool Are the requirements met and the sniff should proceed? |
||
60 | */ |
||
61 | protected function areRequirementsMet(): bool |
||
65 | |||
66 | /** |
||
67 | * Returns an exception handler for the sniffed file. |
||
68 | * |
||
69 | * @return ExceptionHelper Returns the exception helper. |
||
70 | */ |
||
71 | protected function getExceptionHandler(): ExceptionHelper |
||
75 | |||
76 | /** |
||
77 | * Get the sniff name. |
||
78 | * |
||
79 | * @param string|null $sniffName If there is an optional sniff name. |
||
80 | * |
||
81 | * @return string Returns the special sniff name in the code sniffer context. |
||
82 | */ |
||
83 | private function getSniffName(?string $sniffName = null): string |
||
97 | |||
98 | /** |
||
99 | * Returns the used suppress helper. |
||
100 | * |
||
101 | * @return SuppressHelper The suppress helper. |
||
102 | */ |
||
103 | private function getSuppressHelper(): SuppressHelper |
||
111 | |||
112 | /** |
||
113 | * Returns true if this sniff or a rule of this sniff is suppressed with the slevomat suppress annotation. |
||
114 | * |
||
115 | * @param null|string $rule The optional rule. |
||
116 | * |
||
117 | * @return bool Returns true if the sniff is suppressed. |
||
118 | */ |
||
119 | protected function isSniffSuppressed(?string $rule = null): bool |
||
127 | |||
128 | /** |
||
129 | * Called when one of the token types that this sniff is listening for is found. |
||
130 | * |
||
131 | * @param BaseFile $phpcsFile The PHP_CodeSniffer file where the token was found. |
||
132 | * @param int $stackPos The position in the PHP_CodeSniffer file's token stack where the token was found. |
||
133 | * |
||
134 | * @return void |
||
135 | */ |
||
136 | public function process(BaseFile $phpcsFile, $stackPos) |
||
151 | |||
152 | /** |
||
153 | * Processes the token. |
||
154 | * |
||
155 | * @return void |
||
156 | */ |
||
157 | abstract protected function processToken(): void; |
||
158 | |||
159 | /** |
||
160 | * Getter for deferred PHP_CodeSniffer class. |
||
161 | * |
||
162 | * @return File The deferred CodeSniffer file |
||
163 | */ |
||
164 | protected function getFile(): File |
||
168 | |||
169 | /** |
||
170 | * Returns the position of our token in the stack. |
||
171 | * |
||
172 | * @return int The position of our token in the stack. |
||
173 | */ |
||
174 | protected function getStackPosition(): int |
||
178 | |||
179 | /** |
||
180 | * Getter for the used token. |
||
181 | * |
||
182 | * @return array Returns token data of the listened token |
||
183 | */ |
||
184 | protected function getToken(): array |
||
188 | |||
189 | /** |
||
190 | * Do you want to setup things before processing the token? |
||
191 | * |
||
192 | * @return void |
||
193 | */ |
||
194 | protected function setUp(): void |
||
197 | |||
198 | /** |
||
199 | * Is there something to destroy after processing the token? |
||
200 | * |
||
201 | * @return void |
||
202 | */ |
||
203 | protected function tearDown(): void |
||
206 | } |
||
207 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: