Skip to content

Commit ea3ff00

Browse files
committed
Fixed internal error in CommentHelper
1 parent 5cac991 commit ea3ff00

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

SlevomatCodingStandard/Helpers/CommentHelper.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PHP_CodeSniffer\Files\File;
66
use PHP_CodeSniffer\Util\Tokens;
77
use function array_key_exists;
8-
use function array_merge;
8+
use function in_array;
99
use function preg_match;
1010
use function strpos;
1111
use const T_COMMENT;
@@ -38,13 +38,23 @@ public static function getCommentEndPointer(File $phpcsFile, int $commentStartPo
3838
return null;
3939
}
4040

41-
$nextPointerAfterComment = TokenHelper::findNextExcluding(
42-
$phpcsFile,
43-
array_merge([T_COMMENT], Tokens::$phpcsCommentTokens),
44-
$commentStartPointer + 1
45-
);
41+
$commentEndPointer = $commentStartPointer;
42+
43+
for ($i = $commentStartPointer + 1; $i < $phpcsFile->numTokens; $i++) {
44+
if ($tokens[$i]['code'] === T_COMMENT) {
45+
$commentEndPointer = $i;
46+
continue;
47+
}
48+
49+
if (in_array($tokens[$i]['code'], Tokens::$phpcsCommentTokens, true)) {
50+
$commentEndPointer = $i;
51+
continue;
52+
}
53+
54+
break;
55+
}
4656

47-
return $nextPointerAfterComment - 1;
57+
return $commentEndPointer;
4858
}
4959

5060
public static function getMultilineCommentStartPointer(File $phpcsFile, int $commentEndPointer): int

tests/Sniffs/Commenting/data/emptyCommentNoErrors.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@
4141
$some = 'sample_code';
4242
// phpcs:enable
4343
*/
44+
45+
/* not empty
46+
multiline comment */

0 commit comments

Comments
 (0)