Error Identifier: method.deprecated
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 the phpstan-deprecation-rules extension.
Code example #
<?php declare(strict_types = 1);
class UserRepository
{
/** @deprecated Use findById() instead */
public function getUser(int $id): object
{
return $this->findById($id);
}
public function findById(int $id): object
{
// ...
}
}
$repo = new UserRepository();
$repo->getUser(1); // ERROR: Call to deprecated method getUser() of class UserRepository.
Why is it reported? #
A method marked with the @deprecated PHPDoc tag is being called. Deprecated methods are scheduled for removal in a future version and should no longer be used. The deprecation notice typically provides guidance on what to use instead.
How to fix it #
Replace the call with the recommended alternative:
<?php declare(strict_types = 1);
$repo = new UserRepository();
-$repo->getUser(1);
+$repo->findById(1);
How to ignore this error #
You can use the identifier method.deprecated to ignore this error using a comment:
// @phpstan-ignore method.deprecated
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.deprecated