phpstan-strict-rules icon indicating copy to clipboard operation
phpstan-strict-rules copied to clipboard

Feature request: report useless continue statement

Open Slamdunk opened this issue 4 years ago • 2 comments

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.

Slamdunk avatar Apr 14 '20 09:04 Slamdunk

Hi, I don't get it, why is it useless? Because there's no code below in the same foreach?

ondrejmirtes avatar Apr 14 '20 11:04 ondrejmirtes

Exactly. In my experience, useless code is only a smell of a hidden bug.

Slamdunk avatar Apr 15 '20 07:04 Slamdunk