Error Identifier: ignore.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 #
In phpstan.neon:
parameters:
ignoreErrors:
-
message: '#Call to method Foo::bar\(\)#'
path: src/Foo.php
count: 1
This error is reported when the actual number of occurrences does not match the expected count.
Why is it reported? #
The ignored error pattern was expected to match a specific number of times (count), but occurred either more or fewer times than expected. For example, if count: 1 is specified but the error occurs 3 times, this identifier is reported.
This typically happens after code changes – a refactoring might introduce new instances of the error, or fix some of the existing ones, causing the count to drift from the configured value.
How to fix it #
Update the count to match the actual number of occurrences:
parameters:
ignoreErrors:
-
message: '#Call to method Foo::bar\(\)#'
path: src/Foo.php
- count: 1
+ count: 3
Or remove the count parameter to ignore all occurrences of the error:
parameters:
ignoreErrors:
-
message: '#Call to method Foo::bar\(\)#'
path: src/Foo.php
- count: 1
If the ignored error no longer applies, remove the entry entirely. Learn more about ignoring errors in Ignoring Errors.
How to ignore this error #
You can use the identifier ignore.count to ignore this error using a comment:
// @phpstan-ignore ignore.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: ignore.count