Detect dead enum cases
Just my 2 cents: I'm not sure this is a good idea. I once made a PHPStan rule to detect them. And most of the time, our enums are mapped to database state. Not every case is tested. So it will produce lots of errors. I couldn't find anything worth deleting.
@ruudk Thx, I can imagine such problems, but you can always disable the analysis:
ignoreErrors:
- identifier: shipmonk.deadEnumCase
And some codebases may benefit from this. Also, those mapped to database can be easily detected in custom usage provider (assuming Doctrine):
#[Column(type: Types::STRING, enumType: InvoiceStatus::class]
private InvoiceStatus $status;
I just realized that we should indeed create a usage detector, great 😁
I just had an idea, whenever from or tryFrom is called on an enum, we should mark the enum as not dead.
Together with the fact that it's used inside #[Column(enumType: TheEnum::type))
I just had an idea, whenever from or tryFrom is called on an enum, we should mark the enum as not dead.
Together with the fact that it's used inside #[Column(enumType: TheEnum::type))
Both those are already implemented. The only issue with this being enabled by default are typically API input objects, where enums are typically deserialized into the objects. Those cannot be easily natively supported and each app need to add own provider.
Basically, this PR is done and working (I even fully used it in our huge codebase), but I'm still thinking it might be disabled by default.