Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
Throw more specific errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreu Correa Casablanca committed Apr 3, 2017
1 parent f91b9bb commit 348b6b9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/Decimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static function fromFloat(float $fltValue, int $scale = null, bool $remov
if (\is_infinite($fltValue)) {
throw new InfiniteInputError('fltValue must be a finite number');
} elseif (\is_nan($fltValue)) {
throw new NaNInputError("To ensure consistency, this class doesn't handle NaN objects.");
throw new NaNInputError("fltValue can't be NaN");
}

$defaultScale = 16;
Expand Down Expand Up @@ -149,9 +149,7 @@ public static function fromString(string $strValue, int $scale = null, bool $rem
);

} else {
throw new \InvalidArgumentException(
'$strValue must be a string that represents uniquely a finite float point number.'
);
throw new NaNInputError('strValue must be a number');
}

$scale = ($scale!==null) ? $scale : $min_scale;
Expand Down
2 changes: 1 addition & 1 deletion tests/Decimal/DecimalFromFloatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DecimalFromFloatTest extends TestCase
{
/**
* @expectedException \DomainException
* @expectedExceptionMessage To ensure consistency, this class doesn't handle NaN objects.
* @expectedExceptionMessage fltValue can't be NaN
*/
public function testNaN()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Decimal/DecimalFromStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public function testExponentialNotation_With_ZeroExponent()
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage $strValue must be a string that represents uniquely a finite float point number.
* @expectedException \Litipk\BigNumbers\Errors\NaNInputError
* @expectedExceptionMessage strValue must be a number
*/
public function testBadString()
{
Expand Down

0 comments on commit 348b6b9

Please sign in to comment.