Lines
85.71%
6 / 7
Methods
75.00%
3 / 4
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| createReportWireMapper | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| encodeReport | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| decodeReport | 75.00% | 3 / 4 | 0.00% | 0 / 1 | 2.06 | ||
| 15 | final readonly class ReloadCheckReportCodec | |
| 16 | { | |
| 17 | private const int DEPTH = 8; | |
| 18 | ||
| 19 | public function __construct(private WireMapper $reloadCheckReportWireMapper) {} | |
| 20 | ||
| 21 | public static function createReportWireMapper(): WireMapper | |
| 22 | { | |
| 23 | return new WireMapper(new ClassShapeReader(ValueConverterCollection::keyedByHandledClass([]))); | |
| 24 | } | |
| 25 | ||
| 26 | /** @throws JsonException|StewartException */ | |
| 27 | public function encodeReport(ReloadCheckReport $report): string | |
| 28 | { | |
| 29 | return $this->reloadCheckReportWireMapper->encodeObject($report); | |
| 30 | } | |
| 31 | ||
| 32 | /** @throws JsonException|StewartException */ | |
| 33 | public function decodeReport(string $json): ReloadCheckReport | |
| 34 | { | |
| 35 | $data = JsonDecoder::decodeJson($json, self::DEPTH); | |
| 36 | ||
| 37 | if (!\is_array($data)) { | |
| 38 | throw JsonShapeException::wrongType('report', 'an object', get_debug_type($data)); | |
| 39 | } | |
| 40 | ||
| 41 | return $this->reloadCheckReportWireMapper->decodeObject(ReloadCheckReport::class, $data); | |
| 42 | } | |
| 43 | } |