Math icon indicating copy to clipboard operation
Math copied to clipboard

Type hinting PHPStan for Facing

Open ShockedPlot7560 opened this issue 2 years ago • 1 comments

It may be useful to specify the expected return type of Facing functions with: value-of<Facing::ALL>.

This can break many static analyses, because depending on the PHPstan levels, it will carry over if you pass a simple integer into a function accepting just a few values.

I think this option is worth considering, as it could prevent certain runtime errors in the event of an unaccepted value being supplied?

ShockedPlot7560 avatar Oct 08 '23 09:10 ShockedPlot7560

A better option is likely to just turn Facing into an enum. The PHPStan annotations of that sort have caused a great deal of headaches in the past due to easily lost type information when doing almost anything with the values.

dktapps avatar Oct 08 '23 10:10 dktapps