Error Identifier: enum.implementsDeprecatedTrait
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 NewHelper instead */
trait OldHelper
{
public function help(): void
{
// ...
}
}
enum Status implements OldHelper // error
{
case Active;
case Inactive;
}
Why is it reported? #
This error is reported by phpstan/phpstan-deprecation-rules.
The enum references a deprecated trait in its implements clause. The trait has been marked with the @deprecated PHPDoc tag, indicating it is scheduled for removal or replacement. Additionally, traits cannot appear in an implements clause – only interfaces can be implemented.
How to fix it #
Replace the deprecated trait with a non-deprecated interface:
<?php declare(strict_types = 1);
-enum Status implements OldHelper
+enum Status implements NewHelperInterface
{
case Active;
case Inactive;
}
If the trait functionality is needed, use it with the use keyword inside the enum body instead of implements:
<?php declare(strict_types = 1);
-enum Status implements OldHelper
+enum Status
{
+ use NewHelper;
+
case Active;
case Inactive;
}
How to ignore this error #
You can use the identifier enum.implementsDeprecatedTrait to ignore this error using a comment:
// @phpstan-ignore enum.implementsDeprecatedTrait
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.implementsDeprecatedTrait
Rules that report this error #
- PHPStan\Rules\Deprecations\RestrictedDeprecatedClassNameUsageExtension [1] phpstan/phpstan-deprecation-rules