Error Identifier: method.deprecatedInterface
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 NewLogger instead */
interface OldLogger
{
public function log(string $message): void;
}
function doFoo(OldLogger $logger): void
{
$logger->log('hello'); // ERROR: Call to method log() of deprecated interface OldLogger.
}
Why is it reported? #
This error is reported by phpstan/phpstan-deprecation-rules.
A method is being called on an instance typed as an interface that has been marked as @deprecated. Even though the method itself is not deprecated, the entire interface is deprecated, which means all usage of the interface – including calling its methods – should be replaced with the suggested alternative.
How to fix it #
Replace the usage of the deprecated interface with its recommended replacement:
<?php declare(strict_types = 1);
-function doFoo(OldLogger $logger): void
+function doFoo(NewLogger $logger): void
{
$logger->log('hello');
}
How to ignore this error #
You can use the identifier method.deprecatedInterface to ignore this error using a comment:
// @phpstan-ignore method.deprecatedInterface
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: method.deprecatedInterface