Error Identifier: enum.implementsDeprecatedClass
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 */
interface OldContract
{
public function execute(): void;
}
enum Status implements OldContract
{
case Active;
case Inactive;
public function execute(): void
{
}
}
Why is it reported? #
The enum implements an interface that is marked as @deprecated. Using deprecated interfaces couples new code to APIs that are scheduled for removal, making future upgrades harder. This rule is provided by phpstan-deprecation-rules.
How to fix it #
Switch to the non-deprecated replacement interface, if one exists:
-enum Status implements OldContract
+enum Status implements NewContract
{
case Active;
case Inactive;
}
If no replacement exists yet, check the deprecation message for migration guidance.
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