Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize exceptions structure #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/Exception/CurrencyConversionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Exception thrown when an exchange rate is not available.
*/
class CurrencyConversionException extends MoneyException
class CurrencyConversionException extends \RuntimeException implements MoneyException
{
/**
* @var string
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/MoneyException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace Brick\Money\Exception;

/**
* Base class for money exceptions.
* Interface for money exceptions.
*/
abstract class MoneyException extends \Exception
interface MoneyException extends \Throwable
{
}
2 changes: 1 addition & 1 deletion src/Exception/MoneyMismatchException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Exception thrown when a money is not in the expected currency or context.
*/
class MoneyMismatchException extends MoneyException
class MoneyMismatchException extends \DomainException implements MoneyException
{
/**
* @param Currency $expected
Expand Down
84 changes: 42 additions & 42 deletions src/Exception/UnknownCurrencyException.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
<?php
declare(strict_types=1);
namespace Brick\Money\Exception;
/**
* Exception thrown when attempting to create a Currency from an unknown currency code.
*/
class UnknownCurrencyException extends MoneyException
{
/**
* @param string|int $currencyCode
*
* @return UnknownCurrencyException
*/
public static function unknownCurrency($currencyCode) : self
{
return new self('Unknown currency code: ' . $currencyCode);
}
/**
* @param string $countryCode
*
* @return UnknownCurrencyException
*/
public static function noCurrencyForCountry(string $countryCode) : self
{
return new self('No currency found for country ' . $countryCode);
}
/**
* @param string $countryCode
* @param array $currencyCodes
*
* @return UnknownCurrencyException
*/
public static function noSingleCurrencyForCountry(string $countryCode, array $currencyCodes) : self
{
return new self('No single currency for country ' . $countryCode . ': ' . implode(', ', $currencyCodes));
}
}
<?php
Copy link
Contributor Author

@solodkiy solodkiy Oct 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something was wrong with the line endings here.


declare(strict_types=1);

namespace Brick\Money\Exception;

/**
* Exception thrown when attempting to create a Currency from an unknown currency code.
*/
class UnknownCurrencyException extends \DomainException implements MoneyException
{
/**
* @param string|int $currencyCode
*
* @return UnknownCurrencyException
*/
public static function unknownCurrency($currencyCode) : self
{
return new self('Unknown currency code: ' . $currencyCode);
}

/**
* @param string $countryCode
*
* @return UnknownCurrencyException
*/
public static function noCurrencyForCountry(string $countryCode) : self
{
return new self('No currency found for country ' . $countryCode);
}

/**
* @param string $countryCode
* @param array $currencyCodes
*
* @return UnknownCurrencyException
*/
public static function noSingleCurrencyForCountry(string $countryCode, array $currencyCodes) : self
{
return new self('No single currency for country ' . $countryCode . ': ' . implode(', ', $currencyCodes));
}
}