mirror of
https://github.com/archtechx/money.git
synced 2025-12-12 03:14:03 +00:00
update: add dedicated exception class
This commit is contained in:
parent
96786939bd
commit
d6cb1ba6ae
2 changed files with 19 additions and 2 deletions
15
src/Exceptions/CannotExtractCurrencyException.php
Normal file
15
src/Exceptions/CannotExtractCurrencyException.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ArchTech\Money\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class CannotExtractCurrencyException extends Exception
|
||||
{
|
||||
public function __construct(string $message)
|
||||
{
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace ArchTech\Money;
|
||||
|
||||
use ArchTech\Money\Exceptions\CannotExtractCurrencyException;
|
||||
|
||||
class PriceFormatter
|
||||
{
|
||||
/** Format a decimal per the currency's specifications. */
|
||||
|
|
@ -53,13 +55,13 @@ class PriceFormatter
|
|||
&& str_ends_with($formatted, $currency->suffix())
|
||||
) {
|
||||
if ($possibleCurrency) {
|
||||
throw new \Exception('Multiple currencies are using the same prefix and suffix. Please specify the currency of the formatted string.');
|
||||
throw new CannotExtractCurrencyException('Multiple currencies are using the same prefix and suffix. Please specify the currency of the formatted string.');
|
||||
}
|
||||
|
||||
$possibleCurrency = $currency;
|
||||
}
|
||||
}
|
||||
|
||||
return $possibleCurrency ?? throw new \Exception('None of the currencies are using the prefix and suffix that would match with the formatted string.');
|
||||
return $possibleCurrency ?? throw new CannotExtractCurrencyException('None of the currencies are using the prefix and suffix that would match with the formatted string.');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue