Skip to content

Commit

Permalink
Fix allocation when the amount is smaller than the number of ratios
Browse files Browse the repository at this point in the history
  • Loading branch information
sagikazarmark committed Feb 16, 2018
1 parent 1fe4454 commit 4ce781b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Allocation when the amount is smaller than the number of ratios


## [3.1.2] - 2018-02-16

Expand Down
2 changes: 1 addition & 1 deletion src/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public function allocate(array $ratios)
}

for ($i = 0; $this->getCalculator()->compare($remainder, 0) === 1; ++$i) {
if (!$results[$i]->amount) {
if (!$ratios[$i]) {
continue;
}

Expand Down
2 changes: 2 additions & 0 deletions tests/MoneyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ public function allocationExamples()
[5, [0, 0, 1], [0, 0, 5]],
[5, [0, 3, 7], [0, 2, 3]],
[0, [0, 0, 1], [0, 0, 0]],
[2, [1, 1, 1], [1, 1, 0]],
[1, [1, 1], [1, 0]],
];
}

Expand Down

0 comments on commit 4ce781b

Please sign in to comment.