Loop not detected without curly braces
afilina opened this issue · comments
Anna Filina commented
Bug Description
This code reports Using 'break' outside of a loop or switch structure
. I expect no error.
foreach ([] as $v)
if ($v === false) break;
The same with curly braces works as expected.
foreach ([] as $v) {
if ($v === false) break;
}
Environment
Environment | Answer |
---|---|
PHP version | 7.4 (same on 8.2) |
PHP_CodeSniffer version | 3.7.2 |
PHPCSUtils version | 1.0.10 |
PHPCompatibility version | 9.3.5 |
Install type | Composer global |
Tested Against develop
branch?
- I have verified the issue still exists in the
develop
branch of PHPCompatibility.
Juliette commented
Oh and just so you know, it's unlikely this will be solved in PHPCompatibility as determining whether the continue
/break
is used inside a control structure without curly braces is pretty darn hard.
The best way to get round the false positive, for now, is to run the PHPCS native Generic.ControlStructures.InlineControlStructure
auto-fixer over the code base and run PHPCompatibility after that.
Anna Filina commented
Feel free to close it if it's a duplicate.