Error Identifier: class.implementsInternalInterface
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);
// In vendor/some-library/src/InternalInterface.php:
// namespace SomeLibrary;
// /** @internal */
// interface InternalInterface {}
// In your code:
namespace App;
use SomeLibrary\InternalInterface;
class Foo implements InternalInterface // reported
{
}
Why is it reported? #
The interface in the implements clause is marked as @internal by its defining library. Internal symbols are implementation details that can change or be removed without notice in any release. Implementing an internal interface from a third-party package creates a fragile dependency that may break unexpectedly.
How to fix it #
Use a public (non-internal) interface provided by the library instead.
-class Foo implements InternalInterface
+class Foo implements PublicInterface
{
}
If no public alternative exists, consider whether the library provides a different extension mechanism, such as extending a base class or using composition.
How to ignore this error #
You can use the identifier class.implementsInternalInterface to ignore this error using a comment:
// @phpstan-ignore class.implementsInternalInterface
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: class.implementsInternalInterface
Rules that report this error #
- PHPStan\Rules\InternalTag\RestrictedInternalClassNameUsageExtension [1]