|
13 | 13 | use function array_map; |
14 | 14 | use function array_merge; |
15 | 15 | use function array_unique; |
| 16 | +use function implode; |
16 | 17 | use function ltrim; |
17 | 18 | use function preg_match_all; |
18 | 19 | use function sprintf; |
@@ -204,41 +205,42 @@ public function process(File $phpcsFile, $docCommentOpenPointer): void |
204 | 205 |
|
205 | 206 | $docCommentContent = TokenHelper::getContent($phpcsFile, $docCommentOpenPointer, $tokens[$docCommentOpenPointer]['comment_closer']); |
206 | 207 |
|
207 | | - foreach ($correctAnnotationNames as $correctAnnotationName) { |
208 | | - if (preg_match_all('~\{(' . $correctAnnotationName . ')\}~i', $docCommentContent, $matches, PREG_OFFSET_CAPTURE) === 0) { |
| 208 | + if (preg_match_all( |
| 209 | + '~\{(' . implode('|', $correctAnnotationNames) . ')\}~i', |
| 210 | + $docCommentContent, |
| 211 | + $matches, |
| 212 | + PREG_OFFSET_CAPTURE |
| 213 | + ) === 0) { |
| 214 | + return; |
| 215 | + } |
| 216 | + |
| 217 | + foreach ($matches[1] as $match) { |
| 218 | + $correctAnnotationName = $correctAnnotationNames[strtolower($match[0])]; |
| 219 | + |
| 220 | + if ($correctAnnotationName === $match[0]) { |
209 | 221 | continue; |
210 | 222 | } |
211 | 223 |
|
212 | | - foreach ($matches[1] as $match) { |
213 | | - if ($match[0] === $correctAnnotationName) { |
214 | | - continue; |
215 | | - } |
216 | | - |
217 | | - $fix = $phpcsFile->addFixableError( |
218 | | - sprintf('Annotation name is incorrect. Expected %s, found %s.', $correctAnnotationName, $match[0]), |
219 | | - $docCommentOpenPointer, |
220 | | - self::CODE_ANNOTATION_NAME_INCORRECT |
221 | | - ); |
222 | | - if (!$fix) { |
223 | | - continue; |
224 | | - } |
| 224 | + $fix = $phpcsFile->addFixableError( |
| 225 | + sprintf('Annotation name is incorrect. Expected %s, found %s.', $correctAnnotationName, $match[0]), |
| 226 | + $docCommentOpenPointer, |
| 227 | + self::CODE_ANNOTATION_NAME_INCORRECT |
| 228 | + ); |
| 229 | + if (!$fix) { |
| 230 | + continue; |
| 231 | + } |
225 | 232 |
|
226 | | - $phpcsFile->fixer->beginChangeset(); |
| 233 | + $phpcsFile->fixer->beginChangeset(); |
227 | 234 |
|
228 | | - $fixedDocCommentContent = substr($docCommentContent, 0, $match[1]) . $correctAnnotationName . substr( |
229 | | - $docCommentContent, |
230 | | - $match[1] + strlen($match[0]) |
231 | | - ); |
| 235 | + $fixedDocCommentContent = substr($docCommentContent, 0, $match[1]) . $correctAnnotationName . substr( |
| 236 | + $docCommentContent, |
| 237 | + $match[1] + strlen($match[0]) |
| 238 | + ); |
232 | 239 |
|
233 | | - $phpcsFile->fixer->replaceToken($docCommentOpenPointer, $fixedDocCommentContent); |
234 | | - FixerHelper::removeBetweenIncluding( |
235 | | - $phpcsFile, |
236 | | - $docCommentOpenPointer + 1, |
237 | | - $tokens[$docCommentOpenPointer]['comment_closer'] |
238 | | - ); |
| 240 | + $phpcsFile->fixer->replaceToken($docCommentOpenPointer, $fixedDocCommentContent); |
| 241 | + FixerHelper::removeBetweenIncluding($phpcsFile, $docCommentOpenPointer + 1, $tokens[$docCommentOpenPointer]['comment_closer']); |
239 | 242 |
|
240 | | - $phpcsFile->fixer->endChangeset(); |
241 | | - } |
| 243 | + $phpcsFile->fixer->endChangeset(); |
242 | 244 | } |
243 | 245 | } |
244 | 246 |
|
|
0 commit comments