vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.55k stars 659 forks source link

Annotation for methods which can only access state #4586

Open marcosh opened 3 years ago

marcosh commented 3 years ago

Currently in Psalm there exists the psalm-mutation-free and psalm-pure annotations to denote that a method can not perform certain form of side effects.

I would find useful an annotation to denote the fact that a class method is pure when considered as a function from its input and the class state.

This would allow to ensure that the only side effect of a method is accessing the state of the class. Moreover, if the class had all its promerties marked as readonly, then subsequent calls of a method on the same instance of the class would give the same result.

psalm-github-bot[bot] commented 3 years ago

Hey @marcosh, can you reproduce the issue on https://psalm.dev ?