Skip to content

Commit 986eaa1

Browse files
🐛 Fix for custom tag
1 parent f72416d commit 986eaa1

File tree

5 files changed

+79
-15
lines changed

5 files changed

+79
-15
lines changed

SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class DocCommentGroupSameTypeSniff implements Sniff
2020
'@author',
2121
'@category',
2222
'@copyright',
23+
'@covers',
24+
'@dataProvider',
2325
'@deprecated',
2426
'@example',
2527
'@filesource',

SymfonyCustom/Sniffs/WhiteSpace/DocCommentTagSpacingSniff.php

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,44 @@
1010
*/
1111
class DocCommentTagSpacingSniff implements Sniff
1212
{
13+
/**
14+
* A list of PHPDoc tags that are checked.
15+
*
16+
* @var array
17+
*/
18+
public $tags = array(
19+
'@api',
20+
'@author',
21+
'@category',
22+
'@copyright',
23+
'@covers',
24+
'@dataProvider',
25+
'@deprecated',
26+
'@example',
27+
'@filesource',
28+
'@global',
29+
'@ignore',
30+
'@internal',
31+
'@license',
32+
'@link',
33+
'@method',
34+
'@package',
35+
'@param',
36+
'@property',
37+
'@property-read',
38+
'@property-write',
39+
'@return',
40+
'@see',
41+
'@since',
42+
'@source',
43+
'@subpackage',
44+
'@throws',
45+
'@todo',
46+
'@uses',
47+
'@var',
48+
'@version',
49+
);
50+
1351
/**
1452
* Returns an array of tokens this test wants to listen for.
1553
*
@@ -49,22 +87,26 @@ public function process(File $phpcsFile, $stackPtr)
4987
if (true === $fix) {
5088
$phpcsFile->fixer->addContentBefore($stackPtr, ' ');
5189
}
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-
);
90+
} elseif (1 < $tokens[($stackPtr - 1)]['length']) {
91+
$isCustomTag = !in_array($tokens[$stackPtr]['content'], $this->tags);
6092

61-
if (true === $fix) {
62-
$phpcsFile->fixer->replaceToken($stackPtr - 1, ' ');
93+
// Custom tags are not checked cause there is annotation with array params
94+
if (!$isCustomTag) {
95+
$error = 'There should be only one space before a doc comment tag "%s"';
96+
$fix = $phpcsFile->addFixableError(
97+
$error,
98+
($stackPtr + 1),
99+
'DocCommentTagSpacing',
100+
[$tokens[$stackPtr]['content']]
101+
);
102+
103+
if (true === $fix) {
104+
$phpcsFile->fixer->replaceToken($stackPtr - 1, ' ');
105+
}
63106
}
64107
}
65108
}
66109

67-
// No need to check for space after a doc comment tag
68110
if (isset($tokens[($stackPtr + 1)])
69111
&& $tokens[$stackPtr]['line'] === $tokens[($stackPtr + 1)]['line']
70112
&& T_DOC_COMMENT_WHITESPACE === $tokens[($stackPtr + 1)]['code']

SymfonyCustom/Tests/WhiteSpace/DocCommentTagSpacingUnitTest.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ class DocCommentTagSpacingUnitTest
2020
*
2121
* @JMS\Type("string")
2222
* @JMS\SerializedName("libelle")
23+
* @ORM\AttributeOverrides({
24+
* @ORM\AttributeOverride(
25+
* name="email",
26+
* column=@ORM\Column(type="string", name="email", length=255, unique=false, nullable=true)
27+
* ),
28+
* @ORM\AttributeOverride(
29+
* name="emailCanonical",
30+
* column=@ORM\Column(type="string", name="email_canonical", length=255, unique=false, nullable=true)
31+
* )
32+
* })
2333
*/
2434
private $label;
2535

SymfonyCustom/Tests/WhiteSpace/DocCommentTagSpacingUnitTest.inc.fixed

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ class DocCommentTagSpacingUnitTest
2020
*
2121
* @JMS\Type("string")
2222
* @JMS\SerializedName("libelle")
23+
* @ORM\AttributeOverrides({
24+
* @ORM\AttributeOverride(
25+
* name="email",
26+
* column=@ORM\Column(type="string", name="email", length=255, unique=false, nullable=true)
27+
* ),
28+
* @ORM\AttributeOverride(
29+
* name="emailCanonical",
30+
* column=@ORM\Column(type="string", name="email_canonical", length=255, unique=false, nullable=true)
31+
* )
32+
* })
2333
*/
2434
private $label;
2535

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-
29 => 1,
29-
30 => 1,
30-
32 => 1,
31-
36 => 1,
28+
39 => 1,
29+
40 => 1,
30+
42 => 1,
31+
46 => 1,
3232
);
3333
}
3434

0 commit comments

Comments
 (0)