Skip to content

Commit 0bb452b

Browse files
committed
Report correct problem when another tag appears before param tag
1 parent c926d0b commit 0bb452b

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/Standards/Generic/Sniffs/Commenting/DocCommentSniff.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,8 @@ public function process(File $phpcsFile, $stackPtr)
239239
}
240240

241241
if ($tokens[$tag]['content'] === '@param') {
242-
if (($paramGroupid === null
243-
&& empty($tagGroups[$groupid]) === false)
244-
|| ($paramGroupid !== null
245-
&& $paramGroupid !== $groupid)
242+
if ($paramGroupid !== null
243+
&& $paramGroupid !== $groupid
246244
) {
247245
$error = 'Parameter tags must be grouped together in a doc comment';
248246
$phpcsFile->addError($error, $tag, 'ParamGroup');
@@ -251,18 +249,22 @@ public function process(File $phpcsFile, $stackPtr)
251249
if ($paramGroupid === null) {
252250
$paramGroupid = $groupid;
253251
}
254-
} else if ($groupid === $paramGroupid) {
255-
$error = 'Tag cannot be grouped with parameter tags in a doc comment';
256-
$phpcsFile->addError($error, $tag, 'NonParamGroup');
257252
}//end if
258253

259254
$tagGroups[$groupid][] = $tag;
260255
}//end foreach
261256

262-
foreach ($tagGroups as $group) {
257+
foreach ($tagGroups as $groupid => $group) {
263258
$maxLength = 0;
264259
$paddings = [];
265260
foreach ($group as $pos => $tag) {
261+
if ($paramGroupid === $groupid
262+
&& $tokens[$tag]['content'] !== '@param'
263+
) {
264+
$error = 'Tag cannot be grouped with parameter tags in a doc comment';
265+
$phpcsFile->addError($error, $tag, 'NonParamGroup');
266+
}
267+
266268
$tagLength = strlen($tokens[$tag]['content']);
267269
if ($tagLength > $maxLength) {
268270
$maxLength = $tagLength;

src/Standards/Generic/Tests/Commenting/DocCommentUnitTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public function getErrorList()
5353
171 => 3,
5454
179 => 1,
5555
183 => 1,
56-
184 => 1,
57-
185 => 2,
56+
184 => 2,
57+
185 => 1,
5858
186 => 1,
5959
187 => 2,
6060
191 => 1,

0 commit comments

Comments
 (0)