Skip to content

Commit

Permalink
add interface for actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nielsvanpach committed Jan 12, 2024
1 parent a828d56 commit 66529ee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
use Carbon\CarbonImmutable;
use Spatie\Holidays\Data\Holiday;

class CalculateBelgianHolidaysAction
class Belgium implements Executable
{
protected int $year;

/** @return array<Holiday> */
public function execute(int $year): array
{
$this->year = $year;
Expand Down
11 changes: 11 additions & 0 deletions src/Actions/Executable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Spatie\Holidays\Actions;

use Spatie\Holidays\Data\Holiday;

interface Executable
{
/** @return array<Holiday> */
public function execute(int $year): array;
}
4 changes: 2 additions & 2 deletions src/Holidays.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Spatie\Holidays;

use Carbon\CarbonImmutable;
use Spatie\Holidays\Actions\CalculateBelgianHolidaysAction;
use Spatie\Holidays\Actions\Belgium;
use Spatie\Holidays\Data\Holiday;
use Spatie\Holidays\Exceptions\HolidaysException;

Expand Down Expand Up @@ -45,7 +45,7 @@ public function get(): array
protected function calculate(): self
{
$action = match ($this->countryCode) {
'BE' => (new CalculateBelgianHolidaysAction()),
'BE' => new Belgium(),
null => throw HolidaysException::noCountryCode(),
default => throw HolidaysException::unknownCountryCode($this->countryCode),
};
Expand Down

0 comments on commit 66529ee

Please sign in to comment.