Lines 100.00% 8 / 8
Methods 100.00% 8 / 8
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 fromMicroseconds 100.00% 1 / 1 100.00% 1 / 1 1
 toMicroseconds 100.00% 1 / 1 100.00% 1 / 1 1
 plus 100.00% 1 / 1 100.00% 1 / 1 1
 elapsedSince 100.00% 1 / 1 100.00% 1 / 1 1
 isBefore 100.00% 1 / 1 100.00% 1 / 1 1
 isAfter 100.00% 1 / 1 100.00% 1 / 1 1
 equals 100.00% 1 / 1 100.00% 1 / 1 1
7final readonly class MonotonicTime
8{
9    private function __construct(private int $microseconds) {}
10
11    public static function fromMicroseconds(int $microseconds): self
12    {
13        return new self($microseconds);
14    }
15
16    public function toMicroseconds(): int
17    {
18        return $this->microseconds;
19    }
20
21    public function plus(Duration $duration): self
22    {
23        return new self($this->microseconds + $duration->toMicroseconds());
24    }
25
26    public function elapsedSince(self $earlier): Duration
27    {
28        return Duration::microseconds(max(0, $this->microseconds - $earlier->microseconds));
29    }
30
31    public function isBefore(self $other): bool
32    {
33        return $this->microseconds < $other->microseconds;
34    }
35
36    public function isAfter(self $other): bool
37    {
38        return $this->microseconds > $other->microseconds;
39    }
40
41    public function equals(self $other): bool
42    {
43        return $this->microseconds === $other->microseconds;
44    }
45}