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

Commit 348b6b9

Browse files
author
Andreu Correa Casablanca
committed
Throw more specific errors
1 parent f91b9bb commit 348b6b9

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

src/Decimal.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static function fromFloat(float $fltValue, int $scale = null, bool $remov
8484
if (\is_infinite($fltValue)) {
8585
throw new InfiniteInputError('fltValue must be a finite number');
8686
} elseif (\is_nan($fltValue)) {
87-
throw new NaNInputError("To ensure consistency, this class doesn't handle NaN objects.");
87+
throw new NaNInputError("fltValue can't be NaN");
8888
}
8989

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

151151
} else {
152-
throw new \InvalidArgumentException(
153-
'$strValue must be a string that represents uniquely a finite float point number.'
154-
);
152+
throw new NaNInputError('strValue must be a number');
155153
}
156154

157155
$scale = ($scale!==null) ? $scale : $min_scale;

tests/Decimal/DecimalFromFloatTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class DecimalFromFloatTest extends TestCase
1111
{
1212
/**
1313
* @expectedException \DomainException
14-
* @expectedExceptionMessage To ensure consistency, this class doesn't handle NaN objects.
14+
* @expectedExceptionMessage fltValue can't be NaN
1515
*/
1616
public function testNaN()
1717
{

tests/Decimal/DecimalFromStringTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ public function testExponentialNotation_With_ZeroExponent()
103103
}
104104

105105
/**
106-
* @expectedException \InvalidArgumentException
107-
* @expectedExceptionMessage $strValue must be a string that represents uniquely a finite float point number.
106+
* @expectedException \Litipk\BigNumbers\Errors\NaNInputError
107+
* @expectedExceptionMessage strValue must be a number
108108
*/
109109
public function testBadString()
110110
{

0 commit comments

Comments
 (0)