diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 9e9a85533..9934a7972 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -5,7 +5,7 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Exceptions\InvalidYear; -use Spatie\Holidays\Exceptions\UnsupportedCountry; +use Spatie\Holidays\Exceptions\InvalidCountry; abstract class Country { @@ -93,7 +93,7 @@ public static function findOrFail(string $countryCode): Country $country = self::find($countryCode); if (! $country) { - throw UnsupportedCountry::make($countryCode); + throw InvalidCountry::notFound($countryCode); } return $country; diff --git a/src/Countries/SriLanka.php b/src/Countries/SriLanka.php index a94f46cdf..10413e49d 100644 --- a/src/Countries/SriLanka.php +++ b/src/Countries/SriLanka.php @@ -2,7 +2,7 @@ namespace Spatie\Holidays\Countries; -use Spatie\Holidays\Exceptions\UnsupportedCountry; +use Spatie\Holidays\Exceptions\InvalidCountry; class SriLanka extends Country { @@ -16,6 +16,6 @@ protected function allHolidays(int $year): array // Sri lanka has a committee that decides the holidays for the year // instead of following a full moon calendar. - throw UnsupportedCountry::make($this->countryCode()); + throw InvalidCountry::notFound($this->countryCode()); } } diff --git a/src/Countries/Switzerland.php b/src/Countries/Switzerland.php index c2e9d157c..d4d710689 100644 --- a/src/Countries/Switzerland.php +++ b/src/Countries/Switzerland.php @@ -73,7 +73,7 @@ class Switzerland extends Country public function __construct(protected ?string $region = null) { if ($region !== null && ! in_array($region, self::REGIONS)) { - throw InvalidRegion::unsupportedRegion($region); + throw InvalidRegion::notFound($region); } } diff --git a/src/Exceptions/UnsupportedCountry.php b/src/Exceptions/InvalidCountry.php similarity index 59% rename from src/Exceptions/UnsupportedCountry.php rename to src/Exceptions/InvalidCountry.php index 79bcabb34..451910b25 100644 --- a/src/Exceptions/UnsupportedCountry.php +++ b/src/Exceptions/InvalidCountry.php @@ -4,9 +4,9 @@ use RuntimeException; -class UnsupportedCountry extends RuntimeException +class InvalidCountry extends RuntimeException { - public static function make(string $countryCode): self + public static function notFound(string $countryCode): self { return new self("Country code `{$countryCode}` is not supported."); } diff --git a/src/Exceptions/InvalidRegion.php b/src/Exceptions/InvalidRegion.php index 7941fe2b5..d27ed70d7 100644 --- a/src/Exceptions/InvalidRegion.php +++ b/src/Exceptions/InvalidRegion.php @@ -6,13 +6,8 @@ class InvalidRegion extends RuntimeException { - public static function unsupportedRegion(string $region): self + public static function notFound(string $region): self { return new self("Region '$region' is not supported."); } - - public static function unsupportedLocale(string $locale): self - { - return new self("Locale '$locale' is not supported."); - } } diff --git a/tests/Countries/SriLankaTest.php b/tests/Countries/SriLankaTest.php index ab8eefe4a..5989f52e3 100644 --- a/tests/Countries/SriLankaTest.php +++ b/tests/Countries/SriLankaTest.php @@ -2,9 +2,9 @@ namespace Spatie\Holidays\Tests\Countries; -use Spatie\Holidays\Exceptions\UnsupportedCountry; +use Spatie\Holidays\Exceptions\InvalidCountry; use Spatie\Holidays\Holidays; it('cannot calculate sri lanka holidays', function () { Holidays::for(country: 'lk')->get(); -})->throws(UnsupportedCountry::class); +})->throws(InvalidCountry::class); diff --git a/tests/HolidaysTest.php b/tests/HolidaysTest.php index c09d7db67..c5a462123 100644 --- a/tests/HolidaysTest.php +++ b/tests/HolidaysTest.php @@ -5,7 +5,7 @@ use Spatie\Holidays\Countries\Netherlands; use Spatie\Holidays\Exceptions\InvalidLocale; use Spatie\Holidays\Exceptions\InvalidYear; -use Spatie\Holidays\Exceptions\UnsupportedCountry; +use Spatie\Holidays\Exceptions\InvalidCountry; use Spatie\Holidays\Holidays; it('can get all holidays of the current year', function () { @@ -43,7 +43,7 @@ it('cannot get all holidays of an unknown country code', function () { Holidays::for(country: 'unknown'); -})->throws(UnsupportedCountry::class); +})->throws(InvalidCountry::class); it('cannot get holidays for years before 1970', function () { Holidays::for(country: 'be', year: 1969)->get();