|
6 | 6 | use PHP_CodeSniffer\Sniffs\Sniff; |
7 | 7 | use SlevomatCodingStandard\Helpers\ScopeHelper; |
8 | 8 | use SlevomatCodingStandard\Helpers\TokenHelper; |
| 9 | +use const T_CLOSE_PARENTHESIS; |
9 | 10 | use const T_CLOSURE; |
10 | 11 | use const T_DOUBLE_COLON; |
11 | 12 | use const T_EQUAL; |
|
16 | 17 | use const T_OPEN_SHORT_ARRAY; |
17 | 18 | use const T_OPEN_SQUARE_BRACKET; |
18 | 19 | use const T_OPEN_TAG; |
| 20 | +use const T_STATIC; |
19 | 21 | use const T_STRING; |
20 | 22 | use const T_USE; |
21 | 23 | use const T_VARIABLE; |
@@ -161,11 +163,16 @@ private function hasExplicitCreation(File $phpcsFile, int $scopeOpenerPointer, i |
161 | 163 | return true; |
162 | 164 | } |
163 | 165 |
|
164 | | - if ($this->isCreatedInList($phpcsFile, $i, $scopeOpenerPointer)) { |
| 166 | + $staticPointer = TokenHelper::findPreviousEffective($phpcsFile, $i - 1); |
| 167 | + if ($tokens[$staticPointer]['code'] === T_STATIC) { |
| 168 | + return true; |
| 169 | + } |
| 170 | + |
| 171 | + if ($this->isCreatedInForeach($phpcsFile, $i, $scopeCloserPointer)) { |
165 | 172 | return true; |
166 | 173 | } |
167 | 174 |
|
168 | | - if ($this->isCreatedInForeach($phpcsFile, $i, $scopeOpenerPointer)) { |
| 175 | + if ($this->isCreatedInList($phpcsFile, $i, $scopeOpenerPointer)) { |
169 | 176 | return true; |
170 | 177 | } |
171 | 178 |
|
@@ -198,15 +205,15 @@ private function isCreatedInList(File $phpcsFile, int $variablePointer, int $sco |
198 | 205 | return $tokens[$parenthesisOpenerPointer]['bracket_closer'] > $variablePointer; |
199 | 206 | } |
200 | 207 |
|
201 | | - private function isCreatedInForeach(File $phpcsFile, int $variablePointer, int $scopeOpenerPointer): bool |
| 208 | + private function isCreatedInForeach(File $phpcsFile, int $variablePointer, int $scopeCloserPointer): bool |
202 | 209 | { |
203 | 210 | $tokens = $phpcsFile->getTokens(); |
204 | 211 |
|
205 | | - $parenthesisOpenerPointer = TokenHelper::findPrevious($phpcsFile, T_OPEN_PARENTHESIS, $variablePointer - 1, $scopeOpenerPointer); |
206 | | - return $parenthesisOpenerPointer !== null |
207 | | - && array_key_exists('parenthesis_owner', $tokens[$parenthesisOpenerPointer]) |
208 | | - && $tokens[$tokens[$parenthesisOpenerPointer]['parenthesis_owner']]['code'] === T_FOREACH |
209 | | - && $tokens[$parenthesisOpenerPointer]['parenthesis_closer'] > $variablePointer; |
| 212 | + $parenthesisCloserPointer = TokenHelper::findNext($phpcsFile, T_CLOSE_PARENTHESIS, $variablePointer + 1, $scopeCloserPointer); |
| 213 | + return $parenthesisCloserPointer !== null |
| 214 | + && array_key_exists('parenthesis_owner', $tokens[$parenthesisCloserPointer]) |
| 215 | + && $tokens[$tokens[$parenthesisCloserPointer]['parenthesis_owner']]['code'] === T_FOREACH |
| 216 | + && $tokens[$parenthesisCloserPointer]['parenthesis_opener'] < $variablePointer; |
210 | 217 | } |
211 | 218 |
|
212 | 219 | private function isCreatedByReferencedParameterInFunctionCall(File $phpcsFile, int $variablePointer, int $scopeOpenerPointer): bool |
|
0 commit comments