Error Identifier: catch.internalInterface
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);
// Assuming SomeLibrary\InternalException is marked @internal
try {
someLibraryCall();
} catch (\SomeLibrary\InternalException $e) {
// ...
}
Why is it reported? #
The catch block references an interface (or class) that is marked as @internal by its declaring library. Internal types are implementation details not meant for use by external code. Depending on internal types in catch blocks makes the code fragile because the library may rename, remove, or restructure those types without notice.
How to fix it #
Catch the public exception type that the library exposes instead:
<?php declare(strict_types = 1);
try {
someLibraryCall();
-} catch (\SomeLibrary\InternalException $e) {
+} catch (\SomeLibrary\PublicException $e) {
// ...
}
Or catch a broader, public exception type:
<?php declare(strict_types = 1);
try {
someLibraryCall();
-} catch (\SomeLibrary\InternalException $e) {
+} catch (\RuntimeException $e) {
// ...
}
How to ignore this error #
You can use the identifier catch.internalInterface to ignore this error using a comment:
// @phpstan-ignore catch.internalInterface
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: catch.internalInterface
Rules that report this error #
- PHPStan\Rules\InternalTag\RestrictedInternalClassNameUsageExtension [1]