Skip to content

Commit 18a0e54

Browse files
Fix findStartOfStatement inside of switch/case
1 parent e1300d3 commit 18a0e54

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

src/Files/File.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,6 +2313,11 @@ public function findStartOfStatement($start, $ignore=null)
23132313
&& $this->tokens[$i]['code'] !== T_CLOSE_PARENTHESIS
23142314
&& $this->tokens[$i]['code'] !== T_END_NOWDOC
23152315
&& $this->tokens[$i]['code'] !== T_END_HEREDOC
2316+
&& $this->tokens[$i]['code'] !== T_BREAK
2317+
&& $this->tokens[$i]['code'] !== T_RETURN
2318+
&& $this->tokens[$i]['code'] !== T_CONTINUE
2319+
&& $this->tokens[$i]['code'] !== T_THROW
2320+
&& $this->tokens[$i]['code'] !== T_EXIT
23162321
) {
23172322
// Found the end of the previous scope block.
23182323
return $lastNotEmpty;

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ switch ($foo) {
287287
case 1:
288288
switch ($bar) {
289289
case 1:
290-
return;
290+
return 1;
291291
default:
292-
return;
292+
return 3;
293293
}
294294
case 2:
295295
return 2;
@@ -318,3 +318,16 @@ switch ($foo) {
318318
case 2:
319319
return 2;
320320
}
321+
322+
// OK: Every clause terminates
323+
switch ($foo) {
324+
case 1:
325+
switch ($bar) {
326+
case 1:
327+
return 1;
328+
default:
329+
throw new \Exception();
330+
}
331+
case 2:
332+
return 2;
333+
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ switch ($foo) {
290290
case 1:
291291
switch ($bar) {
292292
case 1:
293-
return;
293+
return 1;
294294
default:
295-
return;
295+
return 3;
296296
}
297297
case 2:
298298
return 2;
@@ -321,3 +321,16 @@ switch ($foo) {
321321
case 2:
322322
return 2;
323323
}
324+
325+
// OK: Every clause terminates
326+
switch ($foo) {
327+
case 1:
328+
switch ($bar) {
329+
case 1:
330+
return 1;
331+
default:
332+
throw new \Exception();
333+
}
334+
case 2:
335+
return 2;
336+
}

0 commit comments

Comments
 (0)