Skip to content

Commit

Permalink
Fixed bug #2502 : Generic.WhiteSpace.ScopeIndent false positives with…
Browse files Browse the repository at this point in the history
… nested switch indentation and case fall-through
  • Loading branch information
gsherwood committed May 13, 2019
1 parent 6868096 commit 802e6ef
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #2478 : FunctionCommentThrowTag.WrongNumber when exception is thrown once but built conditionally
- Fixed bug #2479 : Generic.WhiteSpace.ScopeIndent error when using array destructing with exact indent checking
- Fixed bug #2498 : Squiz.Arrays.ArrayDeclaration.MultiLineNotAllowed autofix breaks heredoc
- Fixed bug #2502 : Generic.WhiteSpace.ScopeIndent false positives with nested switch indentation and case fall-through
</notes>
<contents>
<dir name="/">
Expand Down
6 changes: 1 addition & 5 deletions src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -625,11 +625,7 @@ public function process(File $phpcsFile, $stackPtr)
&& $tokens[$checkToken]['scope_closer'] === $checkToken
&& $tokens[$checkToken]['line'] !== $tokens[$tokens[$checkToken]['scope_opener']]['line']))
|| ($checkToken === null
&& isset($openScopes[$i]) === true
|| (isset($tokens[$i]['scope_condition']) === true
&& isset($tokens[$i]['scope_closer']) === true
&& $tokens[$i]['scope_closer'] === $i
&& $tokens[$i]['line'] !== $tokens[$tokens[$i]['scope_opener']]['line']))
&& isset($openScopes[$i]) === true)
) {
if ($this->debug === true) {
if ($checkToken === null) {
Expand Down
13 changes: 13 additions & 0 deletions src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,19 @@ switch($foo)
$value = 0;
}

switch ($x) {
case 'a':
switch ($y) {
case 'c':
return true;
}
case 'b':
switch ($z) {
case 'd':
return true;
}
}

?>

<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,19 @@ switch($foo)
$value = 0;
}

switch ($x) {
case 'a':
switch ($y) {
case 'c':
return true;
}
case 'b':
switch ($z) {
case 'd':
return true;
}
}

?>

<?php
Expand Down
13 changes: 13 additions & 0 deletions src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,19 @@ switch($foo)
$value = 0;
}

switch ($x) {
case 'a':
switch ($y) {
case 'c':
return true;
}
case 'b':
switch ($z) {
case 'd':
return true;
}
}

?>

<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,19 @@ switch($foo)
$value = 0;
}

switch ($x) {
case 'a':
switch ($y) {
case 'c':
return true;
}
case 'b':
switch ($z) {
case 'd':
return true;
}
}

?>

<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc')
1340 => 1,
1342 => 1,
1345 => 1,
1411 => 1,
1412 => 1,
1413 => 1,
1414 => 1,
1424 => 1,
1425 => 1,
1426 => 1,
1427 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit 802e6ef

Please sign in to comment.