Lines
100.00%
5 / 5
Functions and Methods
100.00%
5 / 5
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| OptionalDuration | 100.00% | 5 / 5 | 100.00% | 5 / 5 | 7 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| parse | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 2 | |||||
| off | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| findDuration | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| __toString | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Config; | |
| 6 | ||
| 7 | use Stewart\Contracts\Exception\TimeException; | |
| 8 | use Stewart\Contracts\Time\Duration; | |
| 9 | use Stringable; | |
| 10 | ||
| 11 | final readonly class OptionalDuration implements Stringable | |
| 12 | { | |
| 13 | private function __construct(private ?Duration $duration) {} | |
| 14 | ||
| 15 | /** @throws TimeException */ | |
| 16 | public static function parse(string $text): self | |
| 17 | { | |
| 18 | return StewartConfigSchema::isOff($text) ? self::off() : new self(Duration::parse($text)); | |
| 19 | } | |
| 20 | ||
| 21 | public static function off(): self | |
| 22 | { | |
| 23 | return new self(null); | |
| 24 | } | |
| 25 | ||
| 26 | public function findDuration(): ?Duration | |
| 27 | { | |
| 28 | return $this->duration; | |
| 29 | } | |
| 30 | ||
| 31 | public function __toString(): string | |
| 32 | { | |
| 33 | return $this->duration === null ? StewartConfigSchema::OFF : (string) $this->duration; | |
| 34 | } | |
| 35 | } |