diff --git a/SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php b/SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php index 523cb3a..1f699be 100644 --- a/SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php +++ b/SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php @@ -6,6 +6,7 @@ use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; use SymfonyCustom\Helpers\FixerHelper; use SymfonyCustom\Helpers\SniffHelper; @@ -43,7 +44,11 @@ public function process(File $phpcsFile, $stackPtr): void $commentTagLine = $tokens[$commentTag]['line']; - $previousString = $phpcsFile->findPrevious(T_DOC_COMMENT_STRING, $commentTag, $stackPtr); + $previousString = $phpcsFile->findPrevious( + array_merge(Tokens::$phpcsCommentTokens, [T_DOC_COMMENT_STRING]), + $commentTag, + $stackPtr + ); $previousLine = -1; if (false !== $previousString) { diff --git a/SymfonyCustom/Tests/Commenting/DocCommentGroupSameTypeUnitTest.inc b/SymfonyCustom/Tests/Commenting/DocCommentGroupSameTypeUnitTest.inc index 8634bcc..42b7b34 100644 --- a/SymfonyCustom/Tests/Commenting/DocCommentGroupSameTypeUnitTest.inc +++ b/SymfonyCustom/Tests/Commenting/DocCommentGroupSameTypeUnitTest.inc @@ -74,3 +74,29 @@ * * @param string $b */ + +/** + * An override of Twig's Lexer to add whitespace and new line detection. + * + * Since the regex are using bytes as position, mb_ methods are voluntary not used. + * phpcs:disable SymfonyCustom.PHP.EncourageMultiBytes + * + * @phpstan-type TokenizerOptions = array{ + * tag_comment: array{string, string}, + * tag_block: array{string, string}, + * tag_variable: array{string, string}, + * whitespace_trim: string, + * whitespace_line_trim: string, + * interpolation: array{string, string}, + * } + * @phpstan-type Regex = array{ + * lex_block: string, + * lex_comment: string, + * lex_variable: string, + * operator: string, + * lex_tokens_start: string, + * interpolation_start: string, + * interpolation_end: string, + * lex_block: string, + * } + */ diff --git a/SymfonyCustom/Tests/Commenting/DocCommentGroupSameTypeUnitTest.inc.fixed b/SymfonyCustom/Tests/Commenting/DocCommentGroupSameTypeUnitTest.inc.fixed index c8a2ae3..5c6a746 100644 --- a/SymfonyCustom/Tests/Commenting/DocCommentGroupSameTypeUnitTest.inc.fixed +++ b/SymfonyCustom/Tests/Commenting/DocCommentGroupSameTypeUnitTest.inc.fixed @@ -77,3 +77,29 @@ * * @param string $b */ + +/** + * An override of Twig's Lexer to add whitespace and new line detection. + * + * Since the regex are using bytes as position, mb_ methods are voluntary not used. + * phpcs:disable SymfonyCustom.PHP.EncourageMultiBytes + * + * @phpstan-type TokenizerOptions = array{ + * tag_comment: array{string, string}, + * tag_block: array{string, string}, + * tag_variable: array{string, string}, + * whitespace_trim: string, + * whitespace_line_trim: string, + * interpolation: array{string, string}, + * } + * @phpstan-type Regex = array{ + * lex_block: string, + * lex_comment: string, + * lex_variable: string, + * operator: string, + * lex_tokens_start: string, + * interpolation_start: string, + * interpolation_end: string, + * lex_block: string, + * } + */