Skip to content

Commit 12d33a8

Browse files
Merge pull request #144 from VincentLanglet/phpcsDoc
Avoid false positiv with phpcs tags
2 parents b95b985 + bd5d44b commit 12d33a8

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PHP_CodeSniffer\Files\File;
88
use PHP_CodeSniffer\Sniffs\Sniff;
9+
use PHP_CodeSniffer\Util\Tokens;
910
use SymfonyCustom\Helpers\FixerHelper;
1011
use SymfonyCustom\Helpers\SniffHelper;
1112

@@ -43,7 +44,11 @@ public function process(File $phpcsFile, $stackPtr): void
4344

4445
$commentTagLine = $tokens[$commentTag]['line'];
4546

46-
$previousString = $phpcsFile->findPrevious(T_DOC_COMMENT_STRING, $commentTag, $stackPtr);
47+
$previousString = $phpcsFile->findPrevious(
48+
array_merge(Tokens::$phpcsCommentTokens, [T_DOC_COMMENT_STRING]),
49+
$commentTag,
50+
$stackPtr
51+
);
4752
$previousLine = -1;
4853

4954
if (false !== $previousString) {

SymfonyCustom/Tests/Commenting/DocCommentGroupSameTypeUnitTest.inc

+26
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,29 @@
7474
*
7575
* @param string $b
7676
*/
77+
78+
/**
79+
* An override of Twig's Lexer to add whitespace and new line detection.
80+
*
81+
* Since the regex are using bytes as position, mb_ methods are voluntary not used.
82+
* phpcs:disable SymfonyCustom.PHP.EncourageMultiBytes
83+
*
84+
* @phpstan-type TokenizerOptions = array{
85+
* tag_comment: array{string, string},
86+
* tag_block: array{string, string},
87+
* tag_variable: array{string, string},
88+
* whitespace_trim: string,
89+
* whitespace_line_trim: string,
90+
* interpolation: array{string, string},
91+
* }
92+
* @phpstan-type Regex = array{
93+
* lex_block: string,
94+
* lex_comment: string,
95+
* lex_variable: string,
96+
* operator: string,
97+
* lex_tokens_start: string,
98+
* interpolation_start: string,
99+
* interpolation_end: string,
100+
* lex_block: string,
101+
* }
102+
*/

SymfonyCustom/Tests/Commenting/DocCommentGroupSameTypeUnitTest.inc.fixed

+26
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,29 @@
7777
*
7878
* @param string $b
7979
*/
80+
81+
/**
82+
* An override of Twig's Lexer to add whitespace and new line detection.
83+
*
84+
* Since the regex are using bytes as position, mb_ methods are voluntary not used.
85+
* phpcs:disable SymfonyCustom.PHP.EncourageMultiBytes
86+
*
87+
* @phpstan-type TokenizerOptions = array{
88+
* tag_comment: array{string, string},
89+
* tag_block: array{string, string},
90+
* tag_variable: array{string, string},
91+
* whitespace_trim: string,
92+
* whitespace_line_trim: string,
93+
* interpolation: array{string, string},
94+
* }
95+
* @phpstan-type Regex = array{
96+
* lex_block: string,
97+
* lex_comment: string,
98+
* lex_variable: string,
99+
* operator: string,
100+
* lex_tokens_start: string,
101+
* interpolation_start: string,
102+
* interpolation_end: string,
103+
* lex_block: string,
104+
* }
105+
*/

0 commit comments

Comments
 (0)