Skip to content

Commit 3e326cb

Browse files
committed
Fixed bug #683 : Comments are incorrectly reported by PSR2.ControlStructures.SwitchDeclaration sniff
1 parent 75f38ed commit 3e326cb

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
122122
}
123123
}
124124

125-
$next = $phpcsFile->findNext(T_WHITESPACE, ($opener + 1), null, true);
125+
$next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($opener + 1), null, true);
126126
if ($tokens[$next]['line'] !== ($tokens[$opener]['line'] + 1)) {
127127
$error = 'The '.strtoupper($type).' body must start on the line following the statement';
128128
$fix = $phpcsFile->addFixableError($error, $nextCase, 'SpaceBeforeColon'.strtoupper($type));

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,15 @@ switch ($foo) {
113113
case 3: return 3;
114114
default: $bar = 0;
115115
}
116+
117+
switch ($foo) {
118+
case 'bar': // some comment
119+
echo 'bar';
120+
break;
121+
case 'baz': // other comment
122+
echo 'baz';
123+
break;
124+
default: // other comment
125+
echo 'default';
126+
break;
127+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,15 @@ switch ($foo) {
117117
default:
118118
$bar = 0;
119119
}
120+
121+
switch ($foo) {
122+
case 'bar': // some comment
123+
echo 'bar';
124+
break;
125+
case 'baz': // other comment
126+
echo 'baz';
127+
break;
128+
default: // other comment
129+
echo 'default';
130+
break;
131+
}

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
5454
- Fixed bug #670 : Endless loop in PSR1 SideEffects sniffer if no semicolon after last statement
5555
-- Thanks to Thomas Jarosch for the patch
5656
- Fixed bug #672 : Call-time pass-by-reference false positive
57+
- Fixed bug #683 : Comments are incorrectly reported by PSR2.ControlStructures.SwitchDeclaration sniff
5758
- Fixed bug #687 : ScopeIndent does not check indent correctly for method prefixes like public and abstract
5859
- Fixed bug #689 : False error on some comments after class closing brace
5960
</notes>

0 commit comments

Comments
 (0)