Error Identifier: arguments.count
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);
function add(int $a, int $b): int
{
return $a + $b;
}
add(1);
Why is it reported? #
The number of arguments passed to a function or method does not match its signature. Either too few required arguments were provided, or too many arguments were passed to a function that does not accept them. PHP will throw a fatal error at runtime in either case.
In the example above, add() requires 2 parameters but only 1 is provided.
How to fix it #
Pass the correct number of arguments:
-add(1);
+add(1, 2);
If the parameter should be optional, give it a default value:
-function add(int $a, int $b): int
+function add(int $a, int $b = 0): int
{
return $a + $b;
}
How to ignore this error #
You can use the identifier arguments.count to ignore this error using a comment:
// @phpstan-ignore arguments.count
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: arguments.count
Rules that report this error #
- PHPStan\Rules\Classes\ClassAttributesRule [1] [2] [3]
- PHPStan\Rules\Classes\ClassConstantAttributesRule [1] [2] [3]
- PHPStan\Rules\Classes\InstantiationRule [1] [2] [3]
- PHPStan\Rules\Constants\ConstantAttributesRule [1] [2] [3]
- PHPStan\Rules\EnumCases\EnumCaseAttributesRule [1] [2] [3]
- PHPStan\Rules\Functions\ArrowFunctionAttributesRule [1] [2] [3]
- PHPStan\Rules\Functions\CallCallablesRule [1] [2] [3]
- PHPStan\Rules\Functions\CallToFunctionParametersRule [1] [2] [3]
- PHPStan\Rules\Functions\CallUserFuncRule [1] [2] [3]
- PHPStan\Rules\Functions\ClosureAttributesRule [1] [2] [3]
- PHPStan\Rules\Functions\FunctionAttributesRule [1] [2] [3]
- PHPStan\Rules\Functions\ParamAttributesRule [1] [2] [3]
- PHPStan\Rules\Methods\CallMethodsRule [1] [2] [3]
- PHPStan\Rules\Methods\CallStaticMethodsRule [1] [2] [3]
- PHPStan\Rules\Methods\MethodAttributesRule [1] [2] [3]
- PHPStan\Rules\Properties\PropertyAttributesRule [1] [2] [3]
- PHPStan\Rules\Properties\PropertyHookAttributesRule [1] [2] [3]
- PHPStan\Rules\Traits\TraitAttributesRule [1] [2] [3]