feat(services): add working day determiner factory

This commit is contained in:
Ondrej Vlach 2024-08-07 12:59:22 +02:00
parent 78bb9e6f09
commit 488049d56f
No known key found for this signature in database
GPG Key ID: 7F141CDACEDEE2DE

View File

@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace App\Services\WorkingDays;
use App\Services\WorkingDays\Date\MonToFriWorkingDayDeterminer;
use App\Services\WorkingDays\PublicHolidays\PublicHolidaysStateFactory;
use App\Services\WorkingDays\Utils\MultipleWorkingDayDeterminer;
class WorkingDayDeterminerFactory
{
public function __construct(
private readonly PublicHolidaysStateFactory $publicHolidaysStateFactory,
) {
}
/**
* Create a working day determiner for the given country.
* @param string $countryCode
* @return WorkingDayDeterminerInterface
*/
public function createForCountry(string $countryCode): WorkingDayDeterminerInterface
{
return match ($countryCode) {
'CZ' => new MultipleWorkingDayDeterminer(
[ new MonToFriWorkingDayDeterminer(), $this->publicHolidaysStateFactory->createDeterminerForCountry($countryCode) ],
),
default => throw new \InvalidArgumentException('Unsupported country code'),
};
}
}