Error Identifier: assert.unresolvableType
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 Validator
{
/**
* @phpstan-assert string&int $value
*/
public function assertValid(mixed $value): void
{
}
}
Why is it reported? #
The type used in the @phpstan-assert tag cannot be resolved to a valid type. This usually happens when the asserted type is an impossible intersection (like string&int which can never exist), references an undefined class, or contains a syntax error.
In the example above, string&int is an intersection type that can never be satisfied because no value can be both a string and an int at the same time.
How to fix it #
Use a valid, resolvable type in the assertion:
/**
- * @phpstan-assert string&int $value
+ * @phpstan-assert string $value
*/
public function assertValid(mixed $value): void
{
}
If the intent is to assert a union type, use | instead of &:
- * @phpstan-assert string&int $value
+ * @phpstan-assert string|int $value
How to ignore this error #
You can use the identifier assert.unresolvableType to ignore this error using a comment:
// @phpstan-ignore assert.unresolvableType
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: assert.unresolvableType