Error Identifier: phpstanApi.class
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\Type\FileTypeMapper;
class MyFileTypeMapper extends FileTypeMapper
{
}
Why is it reported? #
The code extends a PHPStan class or uses instanceof against a PHPStan class that is not covered by the backward compatibility promise. The class might change in a minor PHPStan version, which could break your code.
PHPStan marks certain classes with @api to indicate they are safe to extend. Classes without this tag are considered internal and may have their implementation changed in any minor release.
This error is also reported when performing an instanceof check against a PHPStan class that is not covered by the backward compatibility promise.
How to fix it #
Use only classes that are covered by the backward compatibility promise (marked with @api). Check the PHPStan source code to see if the class you want to extend is part of the public API.
<?php declare(strict_types = 1);
-use PHPStan\Type\FileTypeMapper;
-
-class MyFileTypeMapper extends FileTypeMapper
-{
-}
+// Use PHPStan's public API instead of extending internal classes
If you believe the class 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.class to ignore this error using a comment:
// @phpstan-ignore phpstanApi.class
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.class