Error Identifier: methodTag.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.
Code example #
<?php declare(strict_types = 1);
/** @deprecated Use NewService instead */
class OldService
{
}
/**
* @method OldService createService()
*/
class Factory
{
// error: PHPDoc tag @method for createService() references
// deprecated class OldService.
}
Why is it reported? #
The @method PHPDoc tag declares a magic method whose signature references a class that has been marked as @deprecated. Using deprecated classes in new APIs propagates reliance on code that is scheduled for removal, making future migration harder.
How to fix it #
Update the @method tag to reference the replacement class instead of the deprecated one.
/**
- * @method OldService createService()
+ * @method NewService createService()
*/
class Factory
{
}
How to ignore this error #
You can use the identifier methodTag.deprecatedClass to ignore this error using a comment:
// @phpstan-ignore methodTag.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: methodTag.deprecatedClass
Rules that report this error #
- PHPStan\Rules\Deprecations\RestrictedDeprecatedClassNameUsageExtension [1] phpstan/phpstan-deprecation-rules