Error Identifier: varTag.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
{
}
class Foo
{
/** @var OldLogger */
public $logger;
}
Why is it reported? #
This error is reported by the phpstan-deprecation-rules extension.
A @var PHPDoc tag references a deprecated interface. Deprecated interfaces are scheduled for removal or replacement. Referencing them in type annotations propagates the dependency on a deprecated API.
How to fix it #
Update the @var tag to reference the replacement interface:
class Foo
{
- /** @var OldLogger */
+ /** @var NewLogger */
public $logger;
}
If possible, use a native type declaration instead of a @var tag:
class Foo
{
- /** @var OldLogger */
- public $logger;
+ public NewLogger $logger;
}
If the calling code is itself deprecated, the error will not be reported. Mark the class as deprecated if it is part of a deprecation migration:
+/** @deprecated */
class Foo
{
/** @var OldLogger */
public $logger;
}
How to ignore this error #
You can use the identifier varTag.deprecatedInterface to ignore this error using a comment:
// @phpstan-ignore varTag.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: varTag.deprecatedInterface
Rules that report this error #
- PHPStan\Rules\Deprecations\RestrictedDeprecatedClassNameUsageExtension [1] phpstan/phpstan-deprecation-rules