Skip to content

Commit 7a83026

Browse files
🐛 Fix DocCommentTageSpacing rule
1 parent 137a61d commit 7a83026

File tree

4 files changed

+49
-28
lines changed

4 files changed

+49
-28
lines changed

SymfonyCustom/Sniffs/WhiteSpace/DocCommentTagSpacingSniff.php

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,41 @@ public function process(File $phpcsFile, $stackPtr)
3434
{
3535
$tokens = $phpcsFile->getTokens();
3636

37-
if (!isset($tokens[($stackPtr - 1)]) || T_DOC_COMMENT_WHITESPACE !== $tokens[($stackPtr - 1)]['code']) {
38-
$error = 'There should be a space before a doc comment tag "%s"';
39-
$fix = $phpcsFile->addFixableError(
40-
$error,
41-
($stackPtr - 1),
42-
'DocCommentTagSpacing',
43-
array($tokens[$stackPtr]['content'])
44-
);
37+
if (isset($tokens[($stackPtr - 1)])
38+
&& $tokens[$stackPtr]['line'] === $tokens[($stackPtr - 1)]['line']
39+
) {
40+
if (T_DOC_COMMENT_WHITESPACE !== $tokens[($stackPtr - 1)]['code']) {
41+
$error = 'There should be a space before a doc comment tag "%s"';
42+
$fix = $phpcsFile->addFixableError(
43+
$error,
44+
($stackPtr - 1),
45+
'DocCommentTagSpacing',
46+
[$tokens[$stackPtr]['content']]
47+
);
4548

46-
if (true === $fix) {
47-
$phpcsFile->fixer->addContentBefore($stackPtr, ' ');
48-
}
49-
} elseif (1 !== $tokens[($stackPtr - 1)]['length']) {
50-
$error = 'There should be only one space before a doc comment tag "%s"';
51-
$fix = $phpcsFile->addFixableError(
52-
$error,
53-
($stackPtr + 1),
54-
'DocCommentTagSpacing',
55-
array($tokens[$stackPtr]['content'])
56-
);
49+
if (true === $fix) {
50+
$phpcsFile->fixer->addContentBefore($stackPtr, ' ');
51+
}
52+
} elseif (1 !== $tokens[($stackPtr - 1)]['length']) {
53+
$error = 'There should be only one space before a doc comment tag "%s"';
54+
$fix = $phpcsFile->addFixableError(
55+
$error,
56+
($stackPtr + 1),
57+
'DocCommentTagSpacing',
58+
[$tokens[$stackPtr]['content']]
59+
);
5760

58-
if (true === $fix) {
59-
$phpcsFile->fixer->replaceToken($stackPtr - 1, ' ');
61+
if (true === $fix) {
62+
$phpcsFile->fixer->replaceToken($stackPtr - 1, ' ');
63+
}
6064
}
6165
}
6266

6367
// No need to check for space after a doc comment tag
6468
if (isset($tokens[($stackPtr + 1)])
69+
&& $tokens[$stackPtr]['line'] === $tokens[($stackPtr + 1)]['line']
6570
&& T_DOC_COMMENT_WHITESPACE === $tokens[($stackPtr + 1)]['code']
66-
&& 1 !== $tokens[($stackPtr + 1)]['length']
71+
&& 1 < $tokens[($stackPtr + 1)]['length']
6772
) {
6873
$error = 'There should be only one space after a doc comment tag "%s"';
6974
$fix = $phpcsFile->addFixableError(

SymfonyCustom/Tests/WhiteSpace/DocCommentTagSpacingUnitTest.inc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ class DocCommentTagSpacingUnitTest
1313
* @see otherFunctions()
1414
* @see anotherFunctions()
1515
*/
16-
public $variableName = array();
16+
public $variableName = array();
17+
18+
/**
19+
* @var string
20+
*
21+
* @JMS\Type("string")
22+
* @JMS\SerializedName("libelle")
23+
*/
24+
private $label;
1725

1826
/**
1927
* T_VARIABLE check, var in string and in function.

SymfonyCustom/Tests/WhiteSpace/DocCommentTagSpacingUnitTest.inc.fixed

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ class DocCommentTagSpacingUnitTest
1313
* @see otherFunctions()
1414
* @see anotherFunctions()
1515
*/
16-
public $variableName = array();
16+
public $variableName = array();
17+
18+
/**
19+
* @var string
20+
*
21+
* @JMS\Type("string")
22+
* @JMS\SerializedName("libelle")
23+
*/
24+
private $label;
1725

1826
/**
1927
* T_VARIABLE check, var in string and in function.

SymfonyCustom/Tests/WhiteSpace/DocCommentTagSpacingUnitTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public function getErrorList()
2525
11 => 1,
2626
13 => 1,
2727
14 => 1,
28-
21 => 1,
29-
22 => 1,
30-
24 => 1,
31-
28 => 1,
28+
29 => 1,
29+
30 => 1,
30+
32 => 1,
31+
36 => 1,
3232
);
3333
}
3434

0 commit comments

Comments
 (0)