Lines
100.00%
8 / 8
Functions and Methods
100.00%
8 / 8
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| MonotonicTime | 100.00% | 8 / 8 | 100.00% | 8 / 8 | 8 | 100.00% | 1 / 1 | |||
| __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 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Contracts\Time; | |
| 6 | ||
| 7 | final 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 | } |