Menu
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 #
This error is reported when the same enum name is declared in multiple files within the analysed codebase:
// file1.php
<?php declare(strict_types = 1);
namespace App;
enum Status
{
case Active;
case Inactive;
}
// file2.php
<?php declare(strict_types = 1);
namespace App;
enum Status
{
case Pending;
case Completed;
}
Why is it reported? #
The same enum name is declared multiple times within the registered stub files.
How to fix it #
Remove the duplicate enum declaration, keeping only one:
<?php declare(strict_types = 1);
// file2.php
namespace App;
-enum Status
-{
- case Pending;
- case Completed;
-}
If both declarations are intentionally different, rename one of them:
<?php declare(strict_types = 1);
// file2.php
namespace App;
-enum Status
+enum TaskStatus
{
case Pending;
case Completed;
}
How to ignore this error #
You can use the identifier enum.duplicate to ignore this error using a comment:
// @phpstan-ignore enum.duplicate
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: enum.duplicate
Rules that report this error #
- PHPStan\Rules\Classes\DuplicateClassDeclarationRule [1]