| Total Complexity | 6 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 10 | final class Decoder implements DecoderInterface |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var TypeDecoderInterface[] |
||
| 14 | */ |
||
| 15 | private $decoderTypes; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param TypeDecoderInterface[] $decoderTypes |
||
| 19 | */ |
||
| 20 | 3 | public function __construct(array $decoderTypes) |
|
| 25 | } |
||
| 26 | 3 | } |
|
| 27 | |||
| 28 | public function getContentTypes(): array |
||
| 29 | { |
||
| 30 | return array_keys($this->decoderTypes); |
||
| 31 | 1 | } |
|
| 32 | |||
| 33 | 1 | /** |
|
| 34 | * @throws DeserializerLogicException |
||
| 35 | * @throws DeserializerRuntimeException |
||
| 36 | */ |
||
| 37 | public function decode(string $data, string $contentType): array |
||
| 38 | { |
||
| 39 | if (isset($this->decoderTypes[$contentType])) { |
||
| 40 | return $this->decoderTypes[$contentType]->decode($data); |
||
| 41 | } |
||
| 42 | |||
| 43 | throw DeserializerLogicException::createMissingContentType($contentType); |
||
| 44 | } |
||
| 45 | 2 | ||
| 46 | private function addTypeDecoder(TypeDecoderInterface $decoderType): void |
||
| 49 | } |
||
| 50 | } |
||
| 51 |