|
11 | 11 |
|
12 | 12 | use PHP_CodeSniffer\Files\File; |
13 | 13 | use PHP_CodeSniffer\Sniffs\Sniff; |
| 14 | +use PHP_CodeSniffer\Util\Tokens; |
14 | 15 |
|
15 | 16 | /** |
16 | 17 | * Ensures doc blocks follow basic formatting. |
@@ -50,9 +51,18 @@ public function register() |
50 | 51 | */ |
51 | 52 | public function process(File $phpcsFile, $stackPtr) |
52 | 53 | { |
53 | | - $tokens = $phpcsFile->getTokens(); |
54 | | - $commentEnd = $phpcsFile->findNext(T_DOC_COMMENT_CLOSE_TAG, ($stackPtr + 1)); |
55 | | - $commentStart = $tokens[$commentEnd]['comment_opener']; |
| 54 | + $tokens = $phpcsFile->getTokens(); |
| 55 | + |
| 56 | + if (isset($tokens[$stackPtr]['comment_closer']) === false |
| 57 | + || ($tokens[$tokens[$stackPtr]['comment_closer']]['content'] === '' |
| 58 | + && $tokens[$stackPtr]['comment_closer'] === ($phpcsFile->numTokens - 1)) |
| 59 | + ) { |
| 60 | + // Don't process an unfinished comment during live coding. |
| 61 | + return; |
| 62 | + } |
| 63 | + |
| 64 | + $commentStart = $stackPtr; |
| 65 | + $commentEnd = $tokens[$stackPtr]['comment_closer']; |
56 | 66 |
|
57 | 67 | $empty = [ |
58 | 68 | T_DOC_COMMENT_WHITESPACE, |
@@ -463,15 +473,21 @@ public function process(File $phpcsFile, $stackPtr) |
463 | 473 | // Check for a value. No value means no padding needed. |
464 | 474 | $string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $tag, $commentEnd); |
465 | 475 | if ($string !== false && $tokens[$string]['line'] === $tokens[$tag]['line']) { |
466 | | - $paddings[$tag] = strlen($tokens[($tag + 1)]['content']); |
| 476 | + $paddings[$tag] = $tokens[($tag + 1)]['length']; |
467 | 477 | } |
468 | 478 | } |
469 | 479 |
|
470 | 480 | // Check that there was single blank line after the tag block |
471 | | - // but account for a multi-line tag comments. |
| 481 | + // but account for multi-line tag comments. |
| 482 | + $find = Tokens::$phpcsCommentTokens; |
| 483 | + $find[T_DOC_COMMENT_TAG] = T_DOC_COMMENT_TAG; |
| 484 | + |
472 | 485 | $lastTag = $group[$pos]; |
473 | | - $next = $phpcsFile->findNext(T_DOC_COMMENT_TAG, ($lastTag + 3), $commentEnd); |
474 | | - if ($next !== false && $tokens[$next]['column'] === $tokens[$firstTag]['column']) { |
| 486 | + $next = $phpcsFile->findNext($find, ($lastTag + 3), $commentEnd); |
| 487 | + if ($next !== false |
| 488 | + && $tokens[$next]['column'] === $tokens[$firstTag]['column'] |
| 489 | + && in_array($tokens[$lastTag]['content'], $checkTags) === true |
| 490 | + ) { |
475 | 491 | $prev = $phpcsFile->findPrevious([T_DOC_COMMENT_TAG, T_DOC_COMMENT_STRING], ($next - 1), $commentStart); |
476 | 492 | if ($tokens[$next]['line'] !== ($tokens[$prev]['line'] + 2)) { |
477 | 493 | $error = 'There must be a single blank line after a tag group'; |
|
0 commit comments