Error Identifier: phpstanApi.method
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\Analyser\Scope;
class MyRule
{
public function process(Scope $scope): void
{
$scope->someInternalMethod();
}
}
Why is it reported? #
A method is being called on a PHPStan class that is not covered by the backward compatibility promise. Only methods on classes and interfaces marked with the @api PHPDoc tag are considered part of the stable public API. Methods not covered by this promise might change or be removed in minor PHPStan versions without notice.
If you think the method should be covered by the backward compatibility promise, you can open a discussion.
How to fix it #
Use only methods that are part of PHPStan’s public API (those on @api-tagged classes and interfaces). Check the PHPStan documentation or source code for the intended public API alternatives.
<?php declare(strict_types = 1);
use PHPStan\Analyser\Scope;
class MyRule
{
public function process(Scope $scope): void
{
- $scope->someInternalMethod();
+ $scope->getType($expr);
}
}
How to ignore this error #
You can use the identifier phpstanApi.method to ignore this error using a comment:
// @phpstan-ignore phpstanApi.method
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.method