Lines
100.00%
7 / 7
Functions and Methods
100.00%
6 / 6
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| DelaySchedule | 100.00% | 7 / 7 | 100.00% | 6 / 6 | 7 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| after | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| findNextDueAfter | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | |||||
| countMissedBetween | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| describe | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| isRecurring | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Support\Schedule; | |
| 6 | ||
| 7 | use Stewart\Contracts\Exception\TimeException; | |
| 8 | use Stewart\Contracts\Time\Duration; | |
| 9 | use Stewart\Contracts\Time\MonotonicTime; | |
| 10 | ||
| 11 | /** @internal */ | |
| 12 | final readonly class DelaySchedule implements ElapsedSchedule | |
| 13 | { | |
| 14 | private function __construct(public Duration $delay) {} | |
| 15 | ||
| 16 | /** @throws TimeException */ | |
| 17 | public static function after(Duration $delay): self | |
| 18 | { | |
| 19 | return new self($delay->requireAtLeastOneMillisecond('a one-off delay')); | |
| 20 | } | |
| 21 | ||
| 22 | public function findNextDueAfter(MonotonicTime $anchor, MonotonicTime $after): ?MonotonicTime | |
| 23 | { | |
| 24 | $due = $anchor->plus($this->delay); | |
| 25 | ||
| 26 | return $after->isBefore($due) ? $due : null; | |
| 27 | } | |
| 28 | ||
| 29 | public function countMissedBetween(MonotonicTime $due, MonotonicTime $now): int | |
| 30 | { | |
| 31 | return 0; | |
| 32 | } | |
| 33 | ||
| 34 | public function describe(): string | |
| 35 | { | |
| 36 | return 'once in ' . $this->delay->__toString(); | |
| 37 | } | |
| 38 | ||
| 39 | public function isRecurring(): bool | |
| 40 | { | |
| 41 | return false; | |
| 42 | } | |
| 43 | } |