Skip to content

Commit 2acf5b4

Browse files
author
Vincent Langlet
committed
🐛 Handle case previousString is false
1 parent c6c3fe5 commit 2acf5b4

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

Symfony3Custom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,22 @@ public function process(File $phpcsFile, $stackPtr)
8888
$stackPtr
8989
);
9090

91+
$previousLine = -1;
9192
if (false !== $previousString) {
92-
$previousStringLine = $tokens[$previousString]['line'];
93+
$previousLine = $tokens[$previousString]['line'];
94+
$previousElement = $previousString;
95+
}
96+
97+
if (false !== $previousTag) {
9398
$previousTagLine = $tokens[$previousTag]['line'];
94-
$previousLine = max($previousStringLine, $previousTagLine);
9599

100+
if ($previousTagLine > $previousLine) {
101+
$previousLine = $previousTagLine;
102+
$previousElement = $previousTag;
103+
}
104+
}
105+
106+
if ($previousLine >= 0) {
96107
$currentIsCustom = !in_array($currentType, $this->tags);
97108
$previousIsCustom = ('' !== $previousType)
98109
&& !in_array($previousType, $this->tags);
@@ -121,7 +132,7 @@ public function process(File $phpcsFile, $stackPtr)
121132
$phpcsFile->fixer->beginChangeset();
122133
$this->removeLines(
123134
$phpcsFile,
124-
$previousString,
135+
$previousElement,
125136
$previousLine + 1,
126137
$commentTagLine - 1
127138
);
@@ -161,7 +172,7 @@ public function process(File $phpcsFile, $stackPtr)
161172
} else {
162173
$this->removeLines(
163174
$phpcsFile,
164-
$previousString,
175+
$previousElement,
165176
$previousLine + 2,
166177
$commentTagLine - 1
167178
);

Symfony3Custom/Tests/Commenting/DocCommentGroupSameTypeUnitTest.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,8 @@
6161
*
6262
* @param string $a
6363
*/
64+
65+
/**
66+
* @Route("/{id}/")
67+
* @param
68+
*/

Symfony3Custom/Tests/Commenting/DocCommentGroupSameTypeUnitTest.inc.fixed

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,9 @@
6363
*
6464
* @param string $a
6565
*/
66+
67+
/**
68+
* @Route("/{id}/")
69+
*
70+
* @param
71+
*/

Symfony3Custom/Tests/Commenting/DocCommentGroupSameTypeUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function getErrorList()
3232
20 => 1,
3333
29 => 1,
3434
33 => 1,
35+
67 => 1,
3536
);
3637
}
3738

0 commit comments

Comments
 (0)