1 | <?php |
||
20 | abstract class AbstractSniff implements Sniff |
||
21 | { |
||
22 | use SuppressingTrait; |
||
23 | |||
24 | /** |
||
25 | * The used file. |
||
26 | * |
||
27 | * @var File|void |
||
28 | */ |
||
29 | protected $file; |
||
30 | |||
31 | /** |
||
32 | * Position of the listened token. |
||
33 | * |
||
34 | * @var int|void |
||
35 | */ |
||
36 | protected $stackPos; |
||
37 | |||
38 | /** |
||
39 | * The used token. |
||
40 | * |
||
41 | * @var array|void |
||
42 | */ |
||
43 | protected $token; |
||
44 | |||
45 | /** |
||
46 | * All tokens of the class. |
||
47 | * |
||
48 | * @var array|void The tokens of the class. |
||
49 | */ |
||
50 | protected $tokens; |
||
51 | |||
52 | /** |
||
53 | * Adds the pointer to all token data arrays. |
||
54 | * |
||
55 | * @return void |
||
56 | */ |
||
57 | protected function addPointerToTokens(): void |
||
63 | |||
64 | /** |
||
65 | * Returns true if the requirements for this sniff are met. |
||
66 | * |
||
67 | * @return bool Are the requirements met and the sniff should proceed? |
||
68 | */ |
||
69 | protected function areRequirementsMet(): bool |
||
73 | |||
74 | /** |
||
75 | * Default method for fixing exceptions. |
||
76 | * |
||
77 | * @param CodeWarning $exception |
||
78 | * |
||
79 | * @return void |
||
80 | */ |
||
81 | protected function fixDefaultProblem(CodeWarning $exception): void |
||
86 | |||
87 | /** |
||
88 | * Returns an exception handler for the sniffed file. |
||
89 | * |
||
90 | * @return ExceptionHelper Returns the exception helper. |
||
91 | */ |
||
92 | protected function getExceptionHandler(): ExceptionHelper |
||
96 | |||
97 | /** |
||
98 | * Type-safe getter for the file. |
||
99 | * |
||
100 | * @return File |
||
101 | */ |
||
102 | protected function getFile(): File |
||
106 | |||
107 | /** |
||
108 | * Type-safe getter for the stack position. |
||
109 | * |
||
110 | * @return int |
||
111 | */ |
||
112 | protected function getStackPos(): int |
||
116 | |||
117 | /** |
||
118 | * Called when one of the token types that this sniff is listening for is found. |
||
119 | * |
||
120 | * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint |
||
121 | * |
||
122 | * @param BaseFile $phpcsFile The PHP_CodeSniffer file where the token was found. |
||
123 | * @param int $stackPos The position in the PHP_CodeSniffer file's token stack where the token was found. |
||
124 | * |
||
125 | * @return void |
||
126 | */ |
||
127 | public function process(BaseFile $phpcsFile, $stackPos): void |
||
150 | |||
151 | /** |
||
152 | * Processes the token. |
||
153 | * |
||
154 | * @return void |
||
155 | */ |
||
156 | abstract protected function processToken(): void; |
||
157 | |||
158 | /** |
||
159 | * Do you want to setup things before processing the token? |
||
160 | * |
||
161 | * @return void |
||
162 | */ |
||
163 | protected function setUp(): void |
||
166 | |||
167 | /** |
||
168 | * Is there something to destroy after processing the token? |
||
169 | * |
||
170 | * @return void |
||
171 | */ |
||
172 | protected function tearDown(): void |
||
175 | } |
||
176 |
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.