1 | <?php |
||
19 | abstract class AbstractSniff implements Sniff |
||
20 | { |
||
21 | use SuppressingTrait; |
||
22 | |||
23 | /** |
||
24 | * The used file. |
||
25 | * |
||
26 | * @var File|void |
||
27 | */ |
||
28 | protected $file; |
||
29 | |||
30 | /** |
||
31 | * Position of the listened token. |
||
32 | * |
||
33 | * @var int|void |
||
34 | */ |
||
35 | protected $stackPos; |
||
36 | |||
37 | /** |
||
38 | * The used token. |
||
39 | * |
||
40 | * @var array|void |
||
41 | */ |
||
42 | protected $token; |
||
43 | |||
44 | /** |
||
45 | * All tokens of the class. |
||
46 | * |
||
47 | * @var array|void The tokens of the class. |
||
48 | */ |
||
49 | protected $tokens; |
||
50 | |||
51 | /** |
||
52 | * Adds the pointer to all token data arrays. |
||
53 | * |
||
54 | * @return void |
||
55 | */ |
||
56 | protected function addPointerToTokens(): void |
||
62 | |||
63 | /** |
||
64 | * Returns true if the requirements for this sniff are met. |
||
65 | * |
||
66 | * @return bool Are the requirements met and the sniff should proceed? |
||
67 | */ |
||
68 | protected function areRequirementsMet(): bool |
||
72 | |||
73 | /** |
||
74 | * Default method for fixing exceptions. |
||
75 | * |
||
76 | * @param CodeWarning $exception |
||
77 | * |
||
78 | * @return void |
||
79 | */ |
||
80 | protected function fixDefaultProblem(CodeWarning $exception): void |
||
85 | |||
86 | /** |
||
87 | * Returns an exception handler for the sniffed file. |
||
88 | * |
||
89 | * @return ExceptionHelper Returns the exception helper. |
||
90 | */ |
||
91 | protected function getExceptionHandler(): ExceptionHelper |
||
95 | |||
96 | /** |
||
97 | * Type-safe getter for the file. |
||
98 | * |
||
99 | * @return File |
||
100 | */ |
||
101 | protected function getFile(): File |
||
105 | |||
106 | /** |
||
107 | * Type-safe getter for the stack position. |
||
108 | * |
||
109 | * @return int |
||
110 | */ |
||
111 | protected function getStackPos(): int |
||
115 | |||
116 | /** |
||
117 | * Called when one of the token types that this sniff is listening for is found. |
||
118 | * |
||
119 | * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint |
||
120 | * |
||
121 | * @param File $file The PHP_CodeSniffer file where the token was found. |
||
122 | * @param int $stackPos The position in the PHP_CodeSniffer file's token stack where the token was found. |
||
123 | * |
||
124 | * @return void |
||
125 | */ |
||
126 | public function process(File $file, $stackPos): void |
||
149 | |||
150 | /** |
||
151 | * Processes the token. |
||
152 | * |
||
153 | * @return void |
||
154 | */ |
||
155 | abstract protected function processToken(): void; |
||
156 | |||
157 | /** |
||
158 | * Do you want to setup things before processing the token? |
||
159 | * |
||
160 | * @return void |
||
161 | */ |
||
162 | protected function setUp(): void |
||
165 | |||
166 | /** |
||
167 | * Is there something to destroy after processing the token? |
||
168 | * |
||
169 | * @return void |
||
170 | */ |
||
171 | protected function tearDown(): void |
||
174 | } |
||
175 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.