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
Generic/InlineControlStructure: bail early for control structures without body
The sniff now consistently handles all supported control structures
without a body by bailing early. Extending the existing behavior for
`while` and `for` to also include `do while`, `else`, `elseif`, `if`,
and `foreach`.
Previously, the sniff would incorrectly flag these empty control
structures as inline control structures that needed curly braces. For
`else`, `elseif`, `if`, and `foreach`, the fixer would remove the
semicolon and add the curly braces. For `do while`, the fixer would add
the curly braces and keep the semicolon in between the braces. In all
the cases, the resulting code was syntactically correct.
Consider the following example:
```
do ; while ($foo < 5);
```
Previously, PHPCS would flag this as an inline control structure and
PHPCBF would fix it to:
```
do { ;
} while ($foo < 5);
```
Now an empty `do while` is ignored by the sniff (no warnings and no
fixes).
Here is a link showing that control structures without a body are
valid in PHP:
https://3v4l.org/slnYL
And here is a link showing that the way that they were being fixed by
PHPCBF was resulting in valid code (`while` and `for` are not included
below as they were already ignored before this commit):
https://3v4l.org/8k1N3
0 commit comments