Error Identifier: requireExtends.deprecatedClass
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.
This error is reported by phpstan/phpstan-deprecation-rules.
Code example #
<?php declare(strict_types = 1);
/** @deprecated Use NewBase instead */
class OldBase
{
}
/**
* @phpstan-require-extends OldBase
*/
interface HasOldBase
{
}
Why is it reported? #
The @phpstan-require-extends PHPDoc tag references a class that has been marked as deprecated. Using a deprecated class in a require-extends constraint means that any class implementing this interface or using this trait would be required to extend a deprecated class, which should be avoided.
How to fix it #
Update the @phpstan-require-extends tag to reference the non-deprecated replacement class:
<?php declare(strict_types = 1);
/**
- * @phpstan-require-extends OldBase
+ * @phpstan-require-extends NewBase
*/
interface HasOldBase
{
}
How to ignore this error #
You can use the identifier requireExtends.deprecatedClass to ignore this error using a comment:
// @phpstan-ignore requireExtends.deprecatedClass
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: requireExtends.deprecatedClass
Rules that report this error #
- PHPStan\Rules\Deprecations\RestrictedDeprecatedClassNameUsageExtension [1] phpstan/phpstan-deprecation-rules