Lines 100.00% 4 / 4
Functions and Methods 100.00% 4 / 4
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
SunDay 100.00% 4 / 4 100.00% 4 / 4 4 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 forDate 100.00% 1 / 1 100.00% 1 / 1 1
 withEventTime 100.00% 1 / 1 100.00% 1 / 1 1
 findEventTime 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Contracts\Sun;
6
7use DateTimeImmutable;
8use Stewart\Contracts\Time\Instant;
9
10final readonly class SunDay
11{
12    /** @param array<string, Instant> $eventTimes */
13    private function __construct(
14        public DateTimeImmutable $date,
15        private array $eventTimes,
16    ) {}
17
18    public static function forDate(DateTimeImmutable $date): self
19    {
20        return new self($date->setTime(0, 0), []);
21    }
22
23    public function withEventTime(SunEvent $event, Instant $time): self
24    {
25        return new self($this->date, [...$this->eventTimes, $event->value => $time]);
26    }
27
28    public function findEventTime(SunEvent $event): ?Instant
29    {
30        return $this->eventTimes[$event->value] ?? null;
31    }
32}