Error Identifier: phpstanApi.phpstanNamespace
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 PHPStan\Custom;
class MyType
{
}
Why is it reported? #
A third-party package declares classes in the PHPStan\ namespace. This namespace is reserved for PHPStan itself. Declaring classes in this namespace from outside the phpstan/* packages can cause conflicts and is not covered by the backward compatibility promise.
How to fix it #
Move the class to your own namespace:
-namespace PHPStan\Custom;
+namespace MyVendor\PHPStanExtension;
class MyType
{
}
Learn more: Backward Compatibility Promise
How to ignore this error #
You can use the identifier phpstanApi.phpstanNamespace to ignore this error using a comment:
// @phpstan-ignore phpstanApi.phpstanNamespace
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.phpstanNamespace
Rules that report this error #
- PHPStan\Rules\Api\PhpStanNamespaceIn3rdPartyPackageRule [1]