Lines 100.00% 5 / 5
Methods 100.00% 5 / 5
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __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
11final 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}