[4.x] Use RationalMoney when computing modifier totals #16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When working with modifiers, calling
$amount = $amount->plus($modification['amount']);
when computing the total value for the modifiers sometimes results in aRoundingNecessaryException
(Rounding is necessary to represent the result of the operation at this scale).This is because the amount of the modifier can return a
RationalMoney
amount, and the total amount is instanciated as a regularMoney
object, so it does not know how to handle rounding by default.This PR fixes it by instanciating the total as a RationalMoney object instead, which does not result in a rounding exception. This may be a breaking change, but it's the only way we can allow modifiers to return a
RationalMoney
value without crashing.This PR is intended for 4.x-beta versions, but the 4.x stable release will feature a broader rework to move towards a more complete RationalMoney usage.
See #15