Skip to content

Commit

Permalink
Fixed internal error in CommentHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Mar 9, 2024
1 parent 5cac991 commit ea3ff00
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
24 changes: 17 additions & 7 deletions SlevomatCodingStandard/Helpers/CommentHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Tokens;
use function array_key_exists;
use function array_merge;
use function in_array;
use function preg_match;
use function strpos;
use const T_COMMENT;
Expand Down Expand Up @@ -38,13 +38,23 @@ public static function getCommentEndPointer(File $phpcsFile, int $commentStartPo
return null;
}

$nextPointerAfterComment = TokenHelper::findNextExcluding(
$phpcsFile,
array_merge([T_COMMENT], Tokens::$phpcsCommentTokens),
$commentStartPointer + 1
);
$commentEndPointer = $commentStartPointer;

for ($i = $commentStartPointer + 1; $i < $phpcsFile->numTokens; $i++) {
if ($tokens[$i]['code'] === T_COMMENT) {
$commentEndPointer = $i;
continue;
}

if (in_array($tokens[$i]['code'], Tokens::$phpcsCommentTokens, true)) {
$commentEndPointer = $i;
continue;
}

break;
}

return $nextPointerAfterComment - 1;
return $commentEndPointer;
}

public static function getMultilineCommentStartPointer(File $phpcsFile, int $commentEndPointer): int
Expand Down
3 changes: 3 additions & 0 deletions tests/Sniffs/Commenting/data/emptyCommentNoErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@
$some = 'sample_code';
// phpcs:enable
*/

/* not empty
multiline comment */

0 comments on commit ea3ff00

Please sign in to comment.