Lines 100.00% 3 / 3
Functions and Methods 100.00% 3 / 3
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
DaemonStartTime 100.00% 3 / 3 100.00% 3 / 3 3 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 recordStart 100.00% 1 / 1 100.00% 1 / 1 1
 getStartedAt 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Broker;
6
7use LogicException;
8use Stewart\Contracts\Time\Clock;
9use Stewart\Contracts\Time\Instant;
10
11final class DaemonStartTime
12{
13    private ?Instant $startedAt = null;
14
15    public function __construct(private readonly Clock $clock) {}
16
17    public function recordStart(): void
18    {
19        $this->startedAt = $this->clock->getNow();
20    }
21
22    public function getStartedAt(): Instant
23    {
24        return $this->startedAt ?? throw new LogicException('The daemon start time is read before the run started.');
25    }
26}