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
11final readonly class WorkerIdConverter implements ValueConverter
12{
13    private const string EXPECTED = 'a worker index';
14
15    public function handledClass(): string
16    {
17        return WorkerId::class;
18    }
19
20    public function keySuffix(): string
21    {
22        return '';
23    }
24
25    public function encodeValue(object $value): int
26    {
27        \assert($value instanceof WorkerId);
28
29        return $value->value;
30    }
31
32    public function decodeValue(mixed $value, string $path): WorkerId
33    {
34        if (!\is_int($value)) {
35            throw JsonShapeException::wrongType($path, self::EXPECTED, get_debug_type($value));
36        }
37
38        return WorkerId::fromInt($value);
39    }
40}