-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Indention false positive in switch/case/if combination #2414
Comments
I'm trying to replicate this, but I think I might need a larger code snippet. The test file I'm using is: <?php
switch($type)
{
case 'a':
if($operator == '~=') {
$value = true;
break;
}
default:
$value = false;
} PHPCS test output:
So no errors reported from the sniff. Do you have a sample file that I can use to replicate the error? It is possible that the sniff has been confused by something higher up in the file and has calculated the indent incorrectly. |
Here's the whole file:
We use tabs instead of spaces but it's the same with spaces. |
@gsherwood Could you reproduce the issue? |
Thanks for providing that code sample. I can reproduce the issue with the following code: <?php
switch($foo)
{
case 1:
$value = 1; break;
case 2:
if ($bar) {
break;
}
default:
$value = 0;
} |
This issue is caused by the fact that the second case only has a conditional break statement, so the indent is not reset correctly by the time the sniff moves to the default case:
|
This was caused by a bug in the sniff where the break being on the same line as other code caused the sniff to not close the scope of that first case statement. That then caused the sniff to miss the shared closer in the second case statement. |
Thanks for reporting this, and thanks for providing more code to help figure it out. |
system: windows 10 code:
result:
|
The "Generic.Whitespace.ScopeIndent" sniff reports a false indention for switch/case statements that contains an if-condition, e.g.:
Result for line with
default
and below:The text was updated successfully, but these errors were encountered: