Lines 100.00% 4 / 4
Functions and Methods 100.00% 2 / 2
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
WorkerSunCalendarFactory 100.00% 4 / 4 100.00% 2 / 2 3 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 createSunCalendar 100.00% 3 / 3 100.00% 1 / 1 2
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Worker;
6
7use Stewart\Contracts\Sun\SunCalendar;
8use Stewart\Contracts\Time\Clock;
9use Stewart\Runtime\Ipc\Message\Bootstrap;
10use Stewart\Sun\LocatedSunCalendar;
11use Stewart\Sun\NoaaSolarCalculator;
12use Stewart\Sun\UnlocatedSunCalendar;
13
14final readonly class WorkerSunCalendarFactory
15{
16    public function __construct(
17        private Bootstrap $bootstrap,
18        private Clock $clock,
19        private NoaaSolarCalculator $calculator,
20    ) {}
21
22    public function createSunCalendar(): SunCalendar
23    {
24        if ($this->bootstrap->location === null) {
25            return new UnlocatedSunCalendar();
26        }
27
28        return new LocatedSunCalendar($this->bootstrap->location, $this->clock, $this->calculator);
29    }
30}