Error Identifier: interface.extendsDeprecatedTrait
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
{
}
interface MyInterface extends OldHelper // ERROR: Interface MyInterface extends deprecated trait OldHelper.
{
}
Why is it reported? #
This error is reported by phpstan/phpstan-deprecation-rules.
An interface attempts to extend a trait that has been marked as deprecated with the @deprecated PHPDoc tag. While this is already invalid PHP (interfaces cannot extend traits), the deprecation rule also flags that the referenced trait is deprecated and should no longer be used.
How to fix it #
Remove the deprecated trait from the extends clause and extend a proper interface instead:
<?php declare(strict_types = 1);
-interface MyInterface extends OldHelper
+interface MyInterface extends NewHelperInterface
{
}
How to ignore this error #
You can use the identifier interface.extendsDeprecatedTrait to ignore this error using a comment:
// @phpstan-ignore interface.extendsDeprecatedTrait
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: interface.extendsDeprecatedTrait
Rules that report this error #
- PHPStan\Rules\Deprecations\RestrictedDeprecatedClassNameUsageExtension [1] phpstan/phpstan-deprecation-rules