`abstract class Enum` is marked as`@psalm-immutable` which causes errors in PHPStan
We're currently introducing PHPStan's bleeding edge and I see that it started reporting errors like @readonly property cannot have a default value on classes that extend MyCLabs\Enum\Enum. It looks like @psalm-immutable annotation is normalised by PHPStan into readonly state, so cache and instances properties are considered as impure.
Is it possible to improve Enum's phpDocs so PHPStan won't report this errors?
Thanks @mabar for pointing it out on Slack 🍻
I'll be honest, Phpstan and Psalm annotations have been contributed by at least 10 different people, all in different directions.
I merge what gets open and doesn't get any pushback 🤷 Feel free to open a PR if you have a solution to this :)
I think psalm is wrong to not report cache and instances properties.
Why?
- psalm treats properties in immutable classes same way as readonly (or at leasts says so in docs)
- readonly properties should not have any default value, even static ones https://3v4l.org/rucvr#v8.2.1
- while there is no uninitialized state for non-typed properties and they are implicitly null by default,
cacheandinstancesclearly have a different default value
That's why PHPStan reports it. Simplest fix here is to have implicit null as a default value instead of empty array.