Skip to content

Commit 342dbf2

Browse files
committed
Fixed bug #3296 : PSR2.ControlStructures.SwitchDeclaration takes phpcs:ignore as content of case body
1 parent e9a8652 commit 342dbf2

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
2929
- Fixed bug #3294 : Bug in attribute tokenization when content contains PHP end token or attribute closer on new line
3030
-- Thanks to Alessandro Chitolina for the patch
3131
-- Thanks to Juliette Reinders Folmer for the tests
32+
- Fixed bug #3296 : PSR2.ControlStructures.SwitchDeclaration takes phpcs:ignore as content of case body
3233
</notes>
3334
<contents>
3435
<dir name="/">

src/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public function process(File $phpcsFile, $stackPtr)
186186
$nextCode = $this->findNextCase($phpcsFile, ($opener + 1), $nextCloser);
187187
if ($nextCode !== false) {
188188
$prevCode = $phpcsFile->findPrevious(T_WHITESPACE, ($nextCode - 1), $nextCase, true);
189-
if ($tokens[$prevCode]['code'] !== T_COMMENT
189+
if (isset(Tokens::$commentTokens[$tokens[$prevCode]['code']]) === false
190190
&& $this->findNestedTerminator($phpcsFile, ($opener + 1), $nextCode) === false
191191
) {
192192
$error = 'There must be a comment when fall-through is intentional in a non-empty case body';

src/Standards/PSR2/Tests/ControlStructures/SwitchDeclarationUnitTest.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,12 @@ switch ($foo) {
331331
case 2:
332332
return 2;
333333
}
334+
335+
switch ($foo) {
336+
case 1:
337+
// phpcs:ignore
338+
case 2:
339+
return 1;
340+
case 3:
341+
return 2;
342+
}

src/Standards/PSR2/Tests/ControlStructures/SwitchDeclarationUnitTest.inc.fixed

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,12 @@ switch ($foo) {
334334
case 2:
335335
return 2;
336336
}
337+
338+
switch ($foo) {
339+
case 1:
340+
// phpcs:ignore
341+
case 2:
342+
return 1;
343+
case 3:
344+
return 2;
345+
}

0 commit comments

Comments
 (0)