Error Identifier: typeAlias.deprecatedTrait
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 phpstan/phpstan-deprecation-rules.
Code example #
<?php declare(strict_types = 1);
/**
* @deprecated Use NewLoggable instead
*/
trait OldLoggable
{
public function log(string $message): void
{
}
}
/**
* @phpstan-type LoggerType OldLoggable
*/
class Config
{
}
Why is it reported? #
A type alias defined via @phpstan-type references a trait that is marked as @deprecated. Using deprecated symbols in type aliases propagates the dependency on the deprecated code, making future migration harder. Additionally, traits are generally not valid types – they should not be used in type positions.
How to fix it #
Update the type alias to reference the appropriate non-deprecated replacement type.
<?php declare(strict_types = 1);
/**
- * @phpstan-type LoggerType OldLoggable
+ * @phpstan-type LoggerType NewLoggable
*/
class Config
{
}
How to ignore this error #
You can use the identifier typeAlias.deprecatedTrait to ignore this error using a comment:
// @phpstan-ignore typeAlias.deprecatedTrait
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: typeAlias.deprecatedTrait
Rules that report this error #
- PHPStan\Rules\Deprecations\RestrictedDeprecatedClassNameUsageExtension [1] phpstan/phpstan-deprecation-rules