Lines 100.00% 7 / 7
Methods 100.00% 4 / 4
Classes 100.00% 1 / 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 100.00% 3 / 3 100.00% 1 / 1 2
10final readonly class EpochInstantConverter implements ValueConverter
11{
12    public function handledClass(): string
13    {
14        return Instant::class;
15    }
16
17    public function keySuffix(): string
18    {
19        return '_us';
20    }
21
22    public function encodeValue(object $value): int
23    {
24        \assert($value instanceof Instant);
25
26        return $value->toEpochMicroseconds();
27    }
28
29    public function decodeValue(mixed $value, string $path): Instant
30    {
31        return \is_int($value)
32            ? Instant::fromEpochMicroseconds($value)
33            : throw JsonShapeException::wrongType($path, 'a whole number of microseconds since the epoch', get_debug_type($value));
34    }
35}