Skip to content

Commit

Permalink
Fix findStartOfStatement inside of switch/case
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Jan 3, 2021
1 parent e1300d3 commit 18a0e54
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -2313,6 +2313,11 @@ public function findStartOfStatement($start, $ignore=null)
&& $this->tokens[$i]['code'] !== T_CLOSE_PARENTHESIS
&& $this->tokens[$i]['code'] !== T_END_NOWDOC
&& $this->tokens[$i]['code'] !== T_END_HEREDOC
&& $this->tokens[$i]['code'] !== T_BREAK
&& $this->tokens[$i]['code'] !== T_RETURN
&& $this->tokens[$i]['code'] !== T_CONTINUE
&& $this->tokens[$i]['code'] !== T_THROW
&& $this->tokens[$i]['code'] !== T_EXIT
) {
// Found the end of the previous scope block.
return $lastNotEmpty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ switch ($foo) {
case 1:
switch ($bar) {
case 1:
return;
return 1;
default:
return;
return 3;
}
case 2:
return 2;
Expand Down Expand Up @@ -318,3 +318,16 @@ switch ($foo) {
case 2:
return 2;
}

// OK: Every clause terminates
switch ($foo) {
case 1:
switch ($bar) {
case 1:
return 1;
default:
throw new \Exception();
}
case 2:
return 2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ switch ($foo) {
case 1:
switch ($bar) {
case 1:
return;
return 1;
default:
return;
return 3;
}
case 2:
return 2;
Expand Down Expand Up @@ -321,3 +321,16 @@ switch ($foo) {
case 2:
return 2;
}

// OK: Every clause terminates
switch ($foo) {
case 1:
switch ($bar) {
case 1:
return 1;
default:
throw new \Exception();
}
case 2:
return 2;
}

0 comments on commit 18a0e54

Please sign in to comment.