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); // lint >= 8.1
/** @deprecated */
class OldService
{
}
enum Status implements OldService
{
case Active;
}
Why is it reported? #
The enum implements a class that is marked as @deprecated. Internal classes are not intended to be implemented, and using deprecated types couples new code to APIs that are scheduled for removal. This rule is provided by phpstan-deprecation-rules.
Note: triggering this identifier requires an enum to implement a class (not an interface), which PHP itself forbids. PHPStan therefore always also reports a non-ignorable enumImplements.class error alongside this one.
How to fix it #
Remove the deprecated class from the implements clause and use a proper public interface instead:
-enum Status implements OldService
+enum Status implements PublicInterface
{
case Active;
}
How to ignore this error #
You can use the identifier enum.implementsDeprecatedClass to ignore this error using a comment:
// @phpstan-ignore enum.implementsDeprecatedClass
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: enum.implementsDeprecatedClass
Rules that report this error #
- PHPStan\Rules\Deprecations\RestrictedDeprecatedClassNameUsageExtension [1] phpstan/phpstan-deprecation-rules