phpstan-strict-rules
phpstan-strict-rules copied to clipboard
Feature request: report useless continue statement
Hi, the following code doesn't report any warning, but the continue
statement is useless:
$foo = [1, 2, 3];
$bar = [$foo];
foreach ($bar as $var) {
foreach ($var as $number) {
echo $number;
if (2 === $number) {
continue;
}
}
}
https://phpstan.org/r/c86fb5d7-d56f-4fe3-a706-ecf5f65a242b
This can hide a bug, maybe the coder intended a continue 2
, so I'd propose to report this as an error.
Hi, I don't get it, why is it useless? Because there's no code below in the same foreach?
Exactly. In my experience, useless code is only a smell of a hidden bug.