Lines
85.71%
6 / 7
Methods
75.00%
3 / 4
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| 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 | ||
| 12 | final readonly class DateTimeImmutableConverter implements ValueConverter | |
| 13 | { | |
| 14 | public function handledClass(): string | |
| 15 | { | |
| 16 | return DateTimeImmutable::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 DateTimeImmutable); | |
| 27 | ||
| 28 | return CalendarStateFormat::formatDateTime($value); | |
| 29 | } | |
| 30 | ||
| 31 | public function decodeValue(mixed $value, string $path): DateTimeImmutable | |
| 32 | { | |
| 33 | if (!\is_string($value)) { | |
| 34 | throw JsonShapeException::wrongType($path, 'an ISO 8601 date and time', get_debug_type($value)); | |
| 35 | } | |
| 36 | ||
| 37 | return CalendarStateFormat::parseDateTime($value) ?? throw JsonShapeException::unexpectedValue($path, 'an ISO 8601 date and time with an offset', $value); | |
| 38 | } | |
| 39 | } |