Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

abstract class Enum is marked as@psalm-immutable which causes errors in PHPStan #171

Open
Wirone opened this issue Jan 9, 2023 · 2 comments

Comments

@Wirone
Copy link

Wirone commented Jan 9, 2023

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 🍻

@mnapoli
Copy link
Member

mnapoli commented Jan 9, 2023

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 :)

@mabar
Copy link

mabar commented Jan 9, 2023

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, cache and instances clearly 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants