Skip to content

Commit

Permalink
Change Money::dividedBy() parameter order
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Jun 4, 2015
1 parent 4f3095c commit c642d0d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
13 changes: 5 additions & 8 deletions src/BigDecimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,12 @@ public function multipliedBy($that)
* Returns the result of the division of this number and the given one.
*
* @param BigDecimal|number|string $that The number to divide.
* @param integer|null $scale The scale, or null to use the scale of this number.
* @param integer $roundingMode The rounding mode.
* @param int $roundingMode The rounding mode.
* @param int|null $scale The desired scale, or null to use the scale of this number.
*
* @return BigDecimal
*
* @throws ArithmeticException If the divisor is zero or rounding is necessary.
* @throws \InvalidArgumentException If the divisor, the scale or the rounding mode is invalid.
*/
public function dividedBy($that, $scale = null, $roundingMode = RoundingMode::UNNECESSARY)
public function dividedBy($that, $roundingMode = RoundingMode::UNNECESSARY, $scale = null)
{
$that = BigDecimal::of($that);

Expand Down Expand Up @@ -357,7 +354,7 @@ public function withScale($scale, $roundingMode = RoundingMode::UNNECESSARY)
return $this;
}

return $this->dividedBy(1, $scale, $roundingMode);
return $this->dividedBy(1, $roundingMode, $scale);
}

/**
Expand Down Expand Up @@ -626,7 +623,7 @@ public function toBigInteger($roundingMode = RoundingMode::UNNECESSARY)
return BigInteger::of($this->value);
}

return BigInteger::of($this->dividedBy(1, 0, $roundingMode)->value);
return BigInteger::of($this->dividedBy(1, $roundingMode, 0)->value);
}

/**
Expand Down
11 changes: 6 additions & 5 deletions tests/BigDecimalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ public function providerMultipliedBy()
*/
public function testDividedBy($a, $b, $scale, $roundingMode, $unscaledValue, $expectedScale)
{
$decimal = BigDecimal::of($a)->dividedBy($b, $scale, $roundingMode);
$decimal = BigDecimal::of($a)->dividedBy($b, $roundingMode, $scale);
$this->assertBigDecimalEquals($unscaledValue, $expectedScale, $decimal);
}

Expand Down Expand Up @@ -601,7 +601,7 @@ public function providerDividedByZeroThrowsException()
*/
public function testDividedByWithRoundingNecessaryThrowsException($a, $b, $scale)
{
BigDecimal::of($a)->dividedBy($b, $scale);
BigDecimal::of($a)->dividedBy($b, RoundingMode::UNNECESSARY, $scale);
}

/**
Expand All @@ -621,15 +621,15 @@ public function providerDividedByWithRoundingNecessaryThrowsException()
*/
public function testDividedByWithNegativeScaleThrowsException()
{
BigDecimal::of(1)->dividedBy(2, -1);
BigDecimal::of(1)->dividedBy(2, RoundingMode::UNNECESSARY, -1);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testDividedByWithInvalidRoundingModeThrowsException()
{
BigDecimal::of(1)->dividedBy(2, 1, -1);
BigDecimal::of(1)->dividedBy(2, -1);
}

/**
Expand Down Expand Up @@ -664,7 +664,7 @@ private function doTestRoundingMode($roundingMode, BigDecimal $number, $divisor,
$this->setExpectedException(ArithmeticException::class);
}

$actual = $number->dividedBy($divisor, $scale, $roundingMode);
$actual = $number->dividedBy($divisor, $roundingMode, $scale);

if ($expected !== null) {
$this->assertBigDecimalEquals($expected, $scale, $actual);
Expand Down Expand Up @@ -1139,6 +1139,7 @@ public function providerRoundingMode()
[RoundingMode::UNNECESSARY, '-3.501', null, null, null],
];
}

/**
* @dataProvider providerDivideAndRemainder
*
Expand Down

0 comments on commit c642d0d

Please sign in to comment.