Closed C10ne closed 6 months ago
I'm looking for advice on what is the best way to deal with null amounts.
For example, if I have nullable field amount in database, I would do something like:
function getAmount(): ?Money { return $amount ? money($amount, 'USD') : null; } function setAmount(?float $value): void { $amount = $value ? money($value, 'USD')->getValue() : null; }
Otherwise, I get exception that amount is invalid.
Is there another way to handle this case?
Always have a default value for amount, not nullable. Use 0. No amount can be interpreted as the same thing as 0.
I'm looking for advice on what is the best way to deal with null amounts.
For example, if I have nullable field amount in database, I would do something like:
Otherwise, I get exception that amount is invalid.
Is there another way to handle this case?