Error Identifier: phpstanApi.enum
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);
use PHPStan\Node\Expr\TypeExpr;
class Foo
{
public function doFoo(object $o): void
{
if ($o instanceof TypeExpr) {
// ...
}
}
}
Why is it reported? #
The code performs an instanceof check against a PHPStan enum that is not covered by the backward compatibility promise. The enum might change in a minor PHPStan version, which could break your code.
PHPStan marks certain types with @api to indicate they are safe to use in instanceof checks. Enums without this tag are considered internal and may be changed or removed in any minor release.
How to fix it #
Avoid instanceof checks against PHPStan enums that are not part of the public API. Use the documented public API methods instead.
If you believe the enum should be covered by the backward compatibility promise, open a discussion at github.com/phpstan/phpstan/discussions.
Learn more: Backward Compatibility Promise
How to ignore this error #
You can use the identifier phpstanApi.enum to ignore this error using a comment:
// @phpstan-ignore phpstanApi.enum
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: phpstanApi.enum
Rules that report this error #
- PHPStan\Rules\Api\ApiInstanceofRule [1]