Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/Context/CustomContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
use Brick\Math\RoundingMode;
use Brick\Money\Context;
use Brick\Money\Currency;
use Brick\Money\Exception\MoneyException;
use Brick\Money\Exception\InvalidArgumentException;
use Override;

use function sprintf;

/**
* Adjusts a number to a custom scale and optionally step.
*/
Expand All @@ -32,11 +30,11 @@ public function __construct(
) {
/** @psalm-suppress DocblockTypeContradiction, NoValue */
if ($scale < 0) {
throw new MoneyException(sprintf('Invalid scale: %d.', $scale));
throw InvalidArgumentException::invalidScale($scale);
}

if ($step < 1 || ! $this->isValidStepForScale($scale, $step)) {
throw new MoneyException(sprintf('Invalid step: %d.', $step));
throw InvalidArgumentException::invalidStep($step);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Exception/CurrencyConversionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

namespace Brick\Money\Exception;

use RuntimeException;
use Throwable;

use function sprintf;

/**
* Exception thrown when an exchange rate is not available.
*/
final class CurrencyConversionException extends MoneyException
final class CurrencyConversionException extends RuntimeException implements MoneyException
{
public function __construct(
string $message,
Expand Down
23 changes: 23 additions & 0 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Brick\Money\Exception;

use function sprintf;

/**
* Exception thrown when an invalid argument is provided.
*/
final class InvalidArgumentException extends \InvalidArgumentException implements MoneyException
{
public static function invalidScale(int $scale): self
{
return new self(sprintf('Invalid scale: %d.', $scale));
}

public static function invalidStep(int $step): self
{
return new self(sprintf('Invalid step: %d.', $step));
}
}
6 changes: 3 additions & 3 deletions src/Exception/MoneyException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Brick\Money\Exception;

use RuntimeException;
use Throwable;

/**
* Base class for money exceptions.
* Interface for money exceptions.
*/
class MoneyException extends RuntimeException
interface MoneyException extends Throwable
{
}
3 changes: 2 additions & 1 deletion src/Exception/MoneyMismatchException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
namespace Brick\Money\Exception;

use Brick\Money\Currency;
use RuntimeException;

use function sprintf;

/**
* Exception thrown when a money is not in the expected currency or context.
*/
final class MoneyMismatchException extends MoneyException
final class MoneyMismatchException extends RuntimeException implements MoneyException
{
public static function currencyMismatch(Currency $expected, Currency $actual): self
{
Expand Down
4 changes: 3 additions & 1 deletion src/Exception/UnknownCurrencyException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

namespace Brick\Money\Exception;

use RuntimeException;

use function implode;

/**
* Exception thrown when attempting to create a Currency from an unknown currency code.
*/
final class UnknownCurrencyException extends MoneyException
final class UnknownCurrencyException extends RuntimeException implements MoneyException
{
public static function unknownCurrency(string|int $currencyCode): self
{
Expand Down