Open rodrigoprimo opened 5 months ago
I would expect PHPCS to detect the syntax error in both cases (missing semicolon after while closing parenthesis) and to bail instead of attempting to fix the code sample, introducing even more problems.
I think the bailing early should only happen if it is a while
which is part of a do-while
and there is no other code after it, otherwise, the sniff would start to ignore while
structures which are perfectly fine to fix like:
foreach ($array as $item)
while ($i < 5)
if ($test)
echo 'test';
Describe the bug
While working on #482, I found two issues in the Generic.ControlStructures.InlineControlStructure sniff when fixing some do-while statements that contain syntax errors.
Code sample
Code sample 1:
Code sample 2:
To reproduce
Steps to reproduce the behavior:
test.php
with one of the code samples above.phpcbf --standard=Generic --sniffs=Generic.ControlStructures.InlineControlStructure test.php
Modified code sample 1 (note the semicolon and closing curly bracket added after the PHP opening tag):
Modified code sample 2 (note the curly bracket added after the while closing parenthesis and after the if statement):
Expected behavior
I would expect PHPCS to detect the syntax error in both cases (missing semicolon after while closing parenthesis) and to bail instead of attempting to fix the code sample, introducing even more problems.
Versions (please complete the following information)
Please confirm
master
branch of PHP_CodeSniffer.