pmmp / Math

PHP library containing math related code used in PocketMine-MP
GNU Lesser General Public License v3.0
41 stars 20 forks source link

Type hinting PHPStan for Facing #89

Open ShockedPlot7560 opened 11 months ago

ShockedPlot7560 commented 11 months ago

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?

dktapps commented 11 months ago

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.