Error Identifier: selfOut.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 NewClass instead */
class DeprecatedClass {}
class Collection
{
/**
* @phpstan-self-out self<DeprecatedClass>
*/
public function filterDeprecated(): void
{
// ...
}
}
Why is it reported? #
The @phpstan-self-out PHPDoc tag references a class that has been marked as @deprecated. The @phpstan-self-out tag is used to narrow the type of $this after a method call. Referencing a deprecated class in this tag creates a dependency on a symbol that is scheduled for removal or replacement.
How to fix it #
Replace the deprecated class with its non-deprecated replacement in the @phpstan-self-out tag:
<?php declare(strict_types = 1);
class Collection
{
/**
- * @phpstan-self-out self<DeprecatedClass>
+ * @phpstan-self-out self<NewClass>
*/
- public function filterDeprecated(): void
+ public function filterNew(): void
{
// ...
}
}
This error is reported by the phpstan-deprecation-rules extension.
How to ignore this error #
You can use the identifier selfOut.deprecatedClass to ignore this error using a comment:
// @phpstan-ignore selfOut.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: selfOut.deprecatedClass
Rules that report this error #
- PHPStan\Rules\Deprecations\RestrictedDeprecatedClassNameUsageExtension [1] phpstan/phpstan-deprecation-rules