Lines
85.71%
6 / 7
Functions and Methods
75.00%
3 / 4
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| TimeOfDayConverter | 85.71% | 6 / 7 | 75.00% | 3 / 4 | 5.07 | 0.00% | 0 / 1 | |||
| handledClass | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| keySuffix | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| encodeValue | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | |||||
| decodeValue | 66.66% | 2 / 3 | 0.00% | 0 / 1 | 2.15 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Ipc\Wire; | |
| 6 | ||
| 7 | use Stewart\Contracts\Exposure\CalendarStateFormat; | |
| 8 | use Stewart\Contracts\Schedule\TimeOfDay; | |
| 9 | use Stewart\Runtime\Json\ValueConverter; | |
| 10 | use Stewart\Support\Exception\JsonShapeException; | |
| 11 | ||
| 12 | final readonly class TimeOfDayConverter implements ValueConverter | |
| 13 | { | |
| 14 | public function handledClass(): string | |
| 15 | { | |
| 16 | return TimeOfDay::class; | |
| 17 | } | |
| 18 | ||
| 19 | public function keySuffix(): string | |
| 20 | { | |
| 21 | return ''; | |
| 22 | } | |
| 23 | ||
| 24 | public function encodeValue(object $value): string | |
| 25 | { | |
| 26 | \assert($value instanceof TimeOfDay); | |
| 27 | ||
| 28 | return CalendarStateFormat::formatTime($value); | |
| 29 | } | |
| 30 | ||
| 31 | public function decodeValue(mixed $value, string $path): TimeOfDay | |
| 32 | { | |
| 33 | if (!\is_string($value)) { | |
| 34 | throw JsonShapeException::wrongType($path, 'an HH:MM:SS time', get_debug_type($value)); | |
| 35 | } | |
| 36 | ||
| 37 | return CalendarStateFormat::parseTime($value) ?? throw JsonShapeException::unexpectedValue($path, 'an HH:MM:SS time', $value); | |
| 38 | } | |
| 39 | } |