Open Daimona opened 1 year ago
It seems the root cause of this problem might be in splitting the yield
and from
on separate lines. Checking the dump of the $tokens
variable shows the following (part of it):
[11] =>
array(8) {
'type' =>
string(12) "T_YIELD_FROM"
'code' =>
int(282)
'content' =>
string(6) "yield
"
'line' =>
int(4)
'column' =>
int(5)
'length' =>
int(5)
'level' =>
int(1)
'conditions' =>
array(1) {
[2] =>
int(310)
}
}
[12] =>
array(8) {
'type' =>
string(12) "T_YIELD_FROM"
'code' =>
int(282)
'content' =>
string(6) " from"
'line' =>
int(5)
'column' =>
int(1)
'length' =>
int(6)
'level' =>
int(1)
'conditions' =>
array(1) {
[2] =>
int(310)
}
}
Where you can see that both the yield
and the from
are considered to be the same type of token (T_YIELD_FROM
) and that the newline and tabs leading up to it are not parse as individual tokens (T_WHITESPACE
) making for the false positive.
Also checking the PHP.net documentation on tokens you can see on the bottom row of the table that yield from
is a single token.
These observations where done using PHP 8.2.9 and PHPCS on the master branch (commit b0ecdf10f)
Describe the bug Generic.WhiteSpace.ScopeIndent reports multiline
yield from
statements as being incorrectly indented even if the indentation is correct. I've only tested this with tab indentation.Code sample
Custom ruleset
To reproduce Steps to reproduce the behavior:
test.php
with the code sample abovephpcs test.php
On top of that, if you try to autofix the file it will enter an "endless" loop and not do anything:
Expected behavior PHPCS should not report any error. Whether separating
yield
andfrom
is a good idea is beyond the scope of this bug report. However, there's nothing wrong in the code above and the error message is also confusing ("found 2 spaces").Versions (please complete the following information):