Error Identifier: requireExtends.onEnum
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);
/**
* @phpstan-require-extends SomeClass
*/
enum Status
{
case Active;
case Inactive;
}
Why is it reported? #
The @phpstan-require-extends PHPDoc tag is placed on an enum. This tag is only valid on traits and interfaces. Enums in PHP cannot extend classes, so a @phpstan-require-extends constraint on an enum has no meaning and cannot be fulfilled.
How to fix it #
Remove the @phpstan-require-extends tag from the enum:
-/**
- * @phpstan-require-extends SomeClass
- */
enum Status
{
case Active;
case Inactive;
}
If the constraint is needed, move it to a trait or interface that the enum can implement:
/**
* @phpstan-require-extends SomeClass
*/
-enum Status
+interface StatusInterface
{
- case Active;
- case Inactive;
}
How to ignore this error #
You can use the identifier requireExtends.onEnum to ignore this error using a comment:
// @phpstan-ignore requireExtends.onEnum
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: requireExtends.onEnum
Rules that report this error #
- PHPStan\Rules\PhpDoc\RequireExtendsDefinitionClassRule [1]