Error Identifier: interface.extendsDeprecatedInterface
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 NewLoggerInterface instead */
interface OldLoggerInterface
{
public function log(string $message): void;
}
interface MyLoggerInterface extends OldLoggerInterface // ERROR: Interface MyLoggerInterface extends deprecated interface OldLoggerInterface.
{
}
Why is it reported? #
This error is reported by phpstan/phpstan-deprecation-rules.
The interface being extended has been marked as deprecated with the @deprecated PHPDoc tag. Extending a deprecated interface means the child interface inherits a contract that may be removed or changed in a future version of the library. This can lead to breaking changes when the deprecated interface is eventually removed.
How to fix it #
Extend the replacement interface suggested in the deprecation notice:
<?php declare(strict_types = 1);
-interface MyLoggerInterface extends OldLoggerInterface
+interface MyLoggerInterface extends NewLoggerInterface
{
}
If no replacement is available, define the required methods directly on the interface instead of extending the deprecated one:
<?php declare(strict_types = 1);
-interface MyLoggerInterface extends OldLoggerInterface
+interface MyLoggerInterface
{
+ public function log(string $message): void;
}
How to ignore this error #
You can use the identifier interface.extendsDeprecatedInterface to ignore this error using a comment:
// @phpstan-ignore interface.extendsDeprecatedInterface
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.extendsDeprecatedInterface
Rules that report this error #
- PHPStan\Rules\Deprecations\RestrictedDeprecatedClassNameUsageExtension [1] phpstan/phpstan-deprecation-rules