Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nielsvanpach committed Jan 12, 2024
1 parent 9c58f45 commit b7d9ec7
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Calculate public holidays
# Calculate public holidays for a country

[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/holidays.svg?style=flat-square)](https://packagist.org/packages/spatie/holidays)
[![Tests](https://img.shields.io/github/actions/workflow/status/spatie/holidays/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/spatie/holidays/actions/workflows/run-tests.yml)
[![Total Downloads](https://img.shields.io/packagist/dt/spatie/holidays.svg?style=flat-square)](https://packagist.org/packages/spatie/holidays)

**THIS PACKAGE IS IN DEVELOPMENT, DON'T USE IT IN PRODUCTION (YET)**

This package helps to calculate public holidays for a given country.
Calculate which days you don't have to work!

At the moment only Belgium public holidays are supported. You can always send PR with your country. Don't forget to include tests.
At the moment only Belgium public holidays are supported. You can always send a PR with your country. Don't forget to include tests.

```php
use Spatie\Holidays\Holiday;
Expand Down
4 changes: 2 additions & 2 deletions src/Actions/Belgium.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public function execute(int $year): array
protected function ensureYearCanBeCalculated(int $year): void
{
if ($year < 1970) {
throw HolidaysException::yearTooLow($year);
throw HolidaysException::yearTooLow();
}

if ($year > 2037) {
throw HolidaysException::yearTooHigh($year);
throw HolidaysException::yearTooHigh();
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/Enums/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Spatie\Holidays\Actions\Belgium;
use Spatie\Holidays\Actions\Executable;
use Spatie\Holidays\Exceptions\HolidaysException;

enum Country: string
{
Expand All @@ -14,7 +13,6 @@ public function action(): Executable
{
return match ($this) {
self::Belgium => new Belgium(),
null => throw HolidaysException::noCountryCode(),
};
}
}
9 changes: 2 additions & 7 deletions src/Exceptions/HolidaysException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@

class HolidaysException extends RuntimeException
{
public static function noCountryCode(): self
{
return new self("Please provide a country code.");
}

public static function yearTooLow(int $year): self
public static function yearTooLow(): self
{
return new self("Holidays can only be calculated for years after 1970.");
}

public static function yearTooHigh(int $year): self
public static function yearTooHigh(): self
{
return new self("Holidays can only be calculated for years before 2038.");
}
Expand Down
2 changes: 0 additions & 2 deletions src/Holidays.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
namespace Spatie\Holidays;

use Carbon\CarbonImmutable;
use Spatie\Holidays\Actions\Belgium;
use Spatie\Holidays\Enums\Country;
use Spatie\Holidays\Exceptions\HolidaysException;

class Holidays
{
Expand Down
2 changes: 1 addition & 1 deletion tests/HolidaysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

it('cannot get all holidays of an unknown country code', function () {
Holidays::new()->country('unknown')->get();
})->throws(ValueError::class, 'Country code `unknown` is not supported');
})->throws(ValueError::class);

it('cannot get holidays for years before 1970', function () {
Holidays::new()->year(1969)->get();
Expand Down

0 comments on commit b7d9ec7

Please sign in to comment.