Error Identifier: typeAlias.notFound
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);
namespace App;
class Foo
{
/** @phpstan-type MyType string */
}
/**
* @phpstan-import-type UnknownAlias from Foo
*/
class Bar
{
}
Why is it reported? #
A @phpstan-import-type tag is trying to import a type alias that does not exist in the referenced class. The import specifies an alias name, but the target class does not define a type alias with that name via @phpstan-type.
In the example above, Bar attempts to import UnknownAlias from Foo, but Foo only defines a type alias called MyType.
How to fix it #
Use the correct type alias name that exists in the target class:
<?php declare(strict_types = 1);
namespace App;
/**
- * @phpstan-import-type UnknownAlias from Foo
+ * @phpstan-import-type MyType from Foo
*/
class Bar
{
}
Or define the missing type alias in the target class:
<?php declare(strict_types = 1);
namespace App;
/**
* @phpstan-type MyType string
+ * @phpstan-type UnknownAlias int
*/
class Foo
{
}
How to ignore this error #
You can use the identifier typeAlias.notFound to ignore this error using a comment:
// @phpstan-ignore typeAlias.notFound
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.notFound