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);
class SomeClass {}
/**
* @phpstan-type SomeClass string
*/
class AnotherClass
{
}
Why is it reported? #
A type alias defined via @phpstan-type or imported via @phpstan-import-type conflicts with an existing class, interface, trait, or enum name in the current scope. In the example above, defining a type alias named SomeClass conflicts with the existing SomeClass class.
This ambiguity would make it unclear whether SomeClass refers to the actual class or the type alias.
How to fix it #
Choose a different name for the type alias that does not conflict with an existing type:
/**
- * @phpstan-type SomeClass string
+ * @phpstan-type SomeClassAlias string
*/
class AnotherClass
{
}
When using @phpstan-import-type, use the as keyword to rename the imported type alias:
/**
- * @phpstan-import-type SomeClass from AnotherClass
+ * @phpstan-import-type SomeClass from AnotherClass as SomeClassAlias
*/
class Foo
{
}
How to ignore this error #
You can use the identifier typeAlias.duplicate to ignore this error using a comment:
// @phpstan-ignore typeAlias.duplicate
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.duplicate