Lines 87.50% 7 / 8
Methods 75.00% 3 / 4
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 createOverrideWireMapper 100.00% 1 / 1 100.00% 1 / 1 1
 encodeOverride 100.00% 1 / 1 100.00% 1 / 1 1
 decodeOverride 80.00% 4 / 5 0.00% 0 / 1 2.03
18final readonly class AppPauseOverrideCodec
19{
20    private const int DEPTH = 8;
21
22    public function __construct(private WireMapper $appPauseOverrideWireMapper) {}
23
24    public static function createOverrideWireMapper(): WireMapper
25    {
26        return new WireMapper(new ClassShapeReader(ValueConverterCollection::keyedByHandledClass([new IsoInstantConverter()])));
27    }
28
29    /** @throws JsonException|StewartException */
30    public function encodeOverride(AppPauseOverride $override): string
31    {
32        return $this->appPauseOverrideWireMapper->encodeObject(new StoredAppPauseOverride($override->paused, $override->since, $override->source));
33    }
34
35    /** @throws JsonException|StewartException */
36    public function decodeOverride(AppId $appId, string $json): AppPauseOverride
37    {
38        $data = JsonDecoder::decodeJson($json, self::DEPTH);
39
40        if (!\is_array($data)) {
41            throw JsonShapeException::wrongType('override', 'an object', get_debug_type($data));
42        }
43
44        $stored = $this->appPauseOverrideWireMapper->decodeObject(StoredAppPauseOverride::class, $data);
45
46        return new AppPauseOverride($appId, $stored->paused, $stored->since, $stored->source);
47    }
48}