Error Identifier: interface.extendsInternalEnum
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 App;
// In package vendor/some-package:
/** @internal */
enum Status
{
case Active;
case Inactive;
}
// In your code:
interface StatusInterface extends \Vendor\Status
{
}
Why is it reported? #
The interface extends an enum that is marked as @internal. Internal enums are not meant to be used outside the package that defines them. Extending an internal enum couples your code to implementation details that may change without notice in future versions of the package.
How to fix it #
Stop extending the internal enum and use a different approach:
-interface StatusInterface extends \Vendor\Status
+interface StatusInterface
{
+ // Define your own contract instead of relying on internal types
}
If you need to work with values from the internal enum, consider using a public API provided by the package instead.
How to ignore this error #
You can use the identifier interface.extendsInternalEnum to ignore this error using a comment:
// @phpstan-ignore interface.extendsInternalEnum
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: interface.extendsInternalEnum
Rules that report this error #
- PHPStan\Rules\InternalTag\RestrictedInternalClassNameUsageExtension [1]