You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PHPStan (Doctrine Extension) is throwing analyse errors:
------ ----------------------------------------------------------------------------------
Line src/Entity/User.php
------ ----------------------------------------------------------------------------------
18 Property App\Entity\User::$name is never written, only read.
💡 See: https://phpstan.org/developing-extensions/always-read-written-properties
------ ----------------------------------------------------------------------------------
Although my entity is marked as readonly: true PHPStan is still throwing these errors. Reason is, because I have added a constructor which sets the property with an initial ID. If I remove the constructor, everything is fine.
Question might be now:
"Why do you even set any property if your entity is readonly?"
Reason:
This entity is used inside a project which should not be able to persist entity data. I copied this entity from my other project but removed all setters. I kept the constructor to create entities inside my unit tests. But yeah, you would be right here, it still does not really make sense.
Suggestion:
Instead of this misleading error message, which took me hours to realize it probably would be better to write something like:
Entity is marked as readonly but property App\Entity\User::$id is written
What do you think?
The text was updated successfully, but these errors were encountered:
ServerExe
changed the title
Bug: Property is never written, only read - Misleading message when constructor is given
Bug: Property is never written, only read - Misleading message when constructor is given for readonly entity
Jul 18, 2024
ServerExe
changed the title
Bug: Property is never written, only read - Misleading message when constructor is given for readonly entity
Property is never written, only read - Misleading message when constructor is given for readonly entity
Jul 18, 2024
I have a readonly entity:
PHPStan (Doctrine Extension) is throwing analyse errors:
Although my entity is marked as
readonly: true
PHPStan is still throwing these errors. Reason is, because I have added a constructor which sets the property with an initial ID. If I remove the constructor, everything is fine.Question might be now:
"Why do you even set any property if your entity is readonly?"
Reason:
This entity is used inside a project which should not be able to persist entity data. I copied this entity from my other project but removed all setters. I kept the constructor to create entities inside my unit tests. But yeah, you would be right here, it still does not really make sense.
Suggestion:
Instead of this misleading error message, which took me hours to realize it probably would be better to write something like:
What do you think?
The text was updated successfully, but these errors were encountered: