Error Identifier: sealed.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-sealed SomeClass
*/
enum Status
{
case Active;
case Inactive;
}
Why is it reported? #
The @phpstan-sealed PHPDoc tag is placed on an enum. This tag restricts which types can extend or implement a given type, but enums in PHP cannot be extended. Enums are implicitly final, so there are no subtypes to restrict. The @phpstan-sealed tag is only valid on classes and interfaces.
How to fix it #
Remove the @phpstan-sealed tag from the enum:
-/**
- * @phpstan-sealed SomeClass
- */
enum Status
{
case Active;
case Inactive;
}
If sealed type restrictions are needed, use an interface or abstract class instead:
/**
* @phpstan-sealed FooHandler|BarHandler
*/
-enum Status
+interface Handler
{
}
How to ignore this error #
You can use the identifier sealed.onEnum to ignore this error using a comment:
// @phpstan-ignore sealed.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: sealed.onEnum
Rules that report this error #
- PHPStan\Rules\PhpDoc\SealedDefinitionClassRule [1]