moneyphp / money

PHP implementation of Fowler's Money pattern.
http://moneyphp.org
MIT License
4.6k stars 440 forks source link

Magic method RUB, USD, etc does not tell about possible InvalidArgumentException #657

Closed Legion112 closed 1 year ago

Legion112 commented 3 years ago

The magic methods

 * @method static Money AED(string|int $amount)
 * @method static Money ALL(string|int $amount)
 * @method static Money AMD(string|int $amount)
 * @method static Money ANG(string|int $amount)
 * @method static Money AOA(string|int $amount)
 * @method static Money ARS(string|int $amount)
 * @method static Money AUD(string|int $amount)
 * @method static Money AWG(string|int $amount)
 * @method static Money AZN(string|int $amount)
 * @method static Money BAM(string|int $amount)
 * @method static Money BBD(string|int $amount)
 * @method static Money BDT(string|int $amount)
 * @method static Money BGN(string|int $amount)

Do not tell the static analyzer about the possible exception that might be thrown. I recommend rewiring them to the real method with throws doc block.

BonBonSlick commented 2 years ago

true, with ref that // string is accepted if fractional part is zero $fiver = new Money('500.00', new Currency('USD'));

Docs should mention about minimal currency eg CENTS, USD but CENTS. because many devs think as it is, USD = Dollars.

frederikbosch commented 2 years ago

recommend rewiring them to the real method with throws doc block.

How would that look like?

Legion112 commented 2 years ago

How would that look like? Writing method and putting there php throw doc block?

frederikbosch commented 1 year ago

Nothing holds you from using the real constructor new Money(100, new Currency('EUR')) or creating your own factory method/class that adds an @throws. These factory methods are created for IDE and DX purposes. While I was never in favor of this, I believe Mark was right that it was an OK comprise. This issue won't be fixed.