Skip to content

Commit 646524f

Browse files
committed
Merge branch 'switch-return' of https://github.com/klausi/PHP_CodeSniffer
2 parents 37824a6 + a400b78 commit 646524f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
208208
if ($type === 'Case') {
209209
// Ensure the BREAK statement is followed by
210210
// a single blank line, or the end switch brace.
211-
if ($nextLine !== ($breakLine + 2) && $i !== $tokens[$stackPtr]['scope_closer']) {
211+
if ($nextLine !== ($tokens[$semicolon]['line'] + 2) && $i !== $tokens[$stackPtr]['scope_closer']) {
212212
$error = 'Case breaking statements must be followed by a single blank line';
213213
$fix = $phpcsFile->addFixableError($error, $nextBreak, 'SpacingAfterBreak');
214214
if ($fix === true) {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,21 @@ switch ($foo) {
285285
break;
286286

287287
}
288+
289+
// Correct Multi line breaking statement with return.
290+
switch ($foo) {
291+
case 1:
292+
return array(
293+
'whiz',
294+
'bang',
295+
);
296+
297+
case 2:
298+
return helper_func(
299+
'whiz',
300+
'bang'
301+
);
302+
303+
default:
304+
throw new Exception();
305+
}

0 commit comments

Comments
 (0)