Error Identifier: requireImplements.deprecatedEnum
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);
/** @deprecated Use NewInterface instead */
enum Suit: string
{
case Hearts = 'hearts';
case Diamonds = 'diamonds';
}
/**
* @phpstan-require-implements Suit
*/
trait SuitTrait {}
Why is it reported? #
The @phpstan-require-implements PHPDoc tag references an enum that has been marked as @deprecated. Using deprecated symbols in new code perpetuates reliance on APIs that are scheduled for removal or replacement. Since @phpstan-require-implements defines a contract for future use, referencing a deprecated enum in it is especially problematic.
How to fix it #
Replace the deprecated enum with its non-deprecated replacement:
<?php declare(strict_types = 1);
/**
- * @phpstan-require-implements Suit
+ * @phpstan-require-implements NewSuitInterface
*/
trait SuitTrait {}
Note that @phpstan-require-implements can only reference interfaces, not enums. If the enum itself is the intended target, the PHPDoc tag should be changed to reference an interface that the enum implements.
This error is reported by the phpstan-deprecation-rules extension.
How to ignore this error #
You can use the identifier requireImplements.deprecatedEnum to ignore this error using a comment:
// @phpstan-ignore requireImplements.deprecatedEnum
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: requireImplements.deprecatedEnum
Rules that report this error #
- PHPStan\Rules\Deprecations\RestrictedDeprecatedClassNameUsageExtension [1] phpstan/phpstan-deprecation-rules