Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.
Code example #
<?php declare(strict_types = 1);
class Foo
{
private function doFoo(int $input): void
{
while (rand(0, 1)) {
$input = $input + 1;
}
}
}
Why is it reported? #
The private method’s parameter $input is read — but only by $input = $input + 1, whose result no code ever observes. The parameter’s value feeds a closed computation that produces nothing.
This is different from method.unusedParameter, where the parameter is never read at all. Here the value flows through further computation, but that computation is itself dead, so the parameter has no effect on the program.
Only private methods are reported. A public or protected method’s signature may be dictated by an interface, a parent class, or an override, so its parameters cannot always be removed. Magic methods (whose names start with __) are excluded, and the constructor has its own constructor.unusedParameterFlow rule. Parameters referenced by a @phpstan-assert tag or a conditional return type are also not reported.
This rule is part of PHPStan’s dead code analysis. It is reported at rule level 4 and above, and is currently part of Bleeding Edge.
How to fix it #
Remove the parameter and the dead computation if the result is not needed:
- private function doFoo(int $input): void
+ private function doFoo(): void
{
- while (rand(0, 1)) {
- $input = $input + 1;
- }
}
Or use the computed value for something observable if that was the intent:
private function doFoo(int $input): void
{
while (rand(0, 1)) {
$input = $input + 1;
}
+ echo $input;
}
How to ignore this error #
You can use the identifier method.unusedParameterFlow to ignore this error using a comment:
// @phpstan-ignore method.unusedParameterFlow
codeThatProducesTheError();
You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:
parameters:
ignoreErrors:
-
identifier: method.unusedParameterFlow