You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following is a simplified example of a legacy file which I work with and try to validate the changes with PHP_CodeSniffer:
<?phpif (true) {
}
elseif (true) {
}
$a = 1;
The if-else block is indented incorrectly (one level instead of none), the last line is not indented (which is correct). Here's the results which PHP_CodeSniffer produces for this file when checking against PSR2:
↪ scripts/phpcs --version
PHP_CodeSniffer version 2.7.2 (stable) by Squiz (http://www.squiz.net)
↪ scripts/phpcs ~/test.php --standard=PSR2
FILE: /home/morozov/test.php
----------------------------------------------------------------------------------
FOUND 4 ERRORS AND 1 WARNING AFFECTING 4 LINES
----------------------------------------------------------------------------------
3 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 4
4 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 4
4 | ERROR | [x] Expected 1 space after closing brace; newline found
5 | WARNING | [x] Usage of ELSE IF is discouraged; use ELSEIF instead
8 | ERROR | [x] Line indented incorrectly; expected at least 4 spaces, found 0
As you can see, line 8 ($a = 1) is reported as containing error but it's formatted correctly.
Same result is when running with debug output:
↪ scripts/phpcs ~/test.php --standard=PSR2 --runtime-set scope_indent_debug 1
Start with token 0 on line 1 with indent 0
[Line 3] Line indented incorrectly; expected 0 spaces, found 4
=> Add adjustment of -4 for token 3 (T_IF) on line 3
Closing parenthesis found on line 3
* ignoring single-line definition *
Open scope (T_IF) on line 3
=> indent set to 4 by token 9 (T_OPEN_CURLY_BRACKET)
Close scope (T_IF) on line 4
=> indent set to 0 by token 12 (T_CLOSE_CURLY_BRACKET)
[Line 4] Line indented incorrectly; expected 0 spaces, found 4
=> Add adjustment of -4 for token 12 (T_CLOSE_CURLY_BRACKET) on line 4
Closing parenthesis found on line 5
* ignoring single-line definition *
Open scope (T_IF) on line 5
=> indent set to 4 by token 23 (T_OPEN_CURLY_BRACKET)
Close scope (T_IF) on line 6
=> indent set to 4 by token 26 (T_CLOSE_CURLY_BRACKET)
[Line 8] Line indented incorrectly; expected at least 4 spaces, found 0
=> Add adjustment of 4 for token 29 (T_VARIABLE) on line 8
FILE: /home/morozov/test.php
----------------------------------------------------------------------------------
FOUND 4 ERRORS AND 1 WARNING AFFECTING 4 LINES
----------------------------------------------------------------------------------
3 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 4
4 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 4
4 | ERROR | [x] Expected 1 space after closing brace; newline found
5 | WARNING | [x] Usage of ELSE IF is discouraged; use ELSEIF instead
8 | ERROR | [x] Line indented incorrectly; expected at least 4 spaces, found 0
----------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------
Time: 17ms; Memory: 4Mb
Surprisingly, removing the else block or replacing else if with elseif fixes the issue, so it must be a corner case.
The text was updated successfully, but these errors were encountered:
I think the error is caused by the T_ELSE token not being a scope opener in the example code. Changing it to T_ELSEIF makes it a scope opener and the standard rules apply. Having it on the same line as the closing brace of the T_IF also fixes this issue, so I think it's specific to this formatting of code and an exception can be coded in.
Uh oh!
There was an error while loading. Please reload this page.
The following is a simplified example of a legacy file which I work with and try to validate the changes with PHP_CodeSniffer:
The
if-else
block is indented incorrectly (one level instead of none), the last line is not indented (which is correct). Here's the results which PHP_CodeSniffer produces for this file when checking against PSR2:As you can see, line 8 (
$a = 1
) is reported as containing error but it's formatted correctly.Same result is when running with debug output:
Surprisingly, removing the
else
block or replacingelse if
withelseif
fixes the issue, so it must be a corner case.The text was updated successfully, but these errors were encountered: