-
Hello people I have not been using psalm for very long and I was hoping you could give me a tip on how to properly handle the error Psalm identified. Thanks a lot in advance^^ https://psalm.dev/r/1b651c8b27
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
In theory, this is what you want: I made two changes:
The last part is required by Psalm because it's not safe to try to assert types on methods that are subject to be changed. However, your class is very much not immutable because you save things in a property. That makes the whole pattern pretty risky in terms of static analysis (for example, you could imagine calling load a second time with an invalid input that would completely change the first assertion or you could call another method on $foo that could have an effect on $this->data and change the assumption) So Psalm is not letting you do it. There's no safe way to document your code as is |
Beta Was this translation helpful? Give feedback.
In theory, this is what you want:
https://psalm.dev/r/191c5d72a9
I made two changes:
The last part is required by Psalm because it's not safe to try to assert types on methods that are subject to be changed.
However, your class is very much not immutable because you save things in a property.
That makes the whole pattern pretty risky in terms of static analysis (for example, you could imagine calling load a second time with an invalid input that would completely change the first assertion or you could call another method on $foo that could have an effect …