| Total Complexity | 6 |
| Total Lines | 38 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | final class Encoder implements EncoderInterface |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var TypeEncoderInterface[] |
||
| 13 | */ |
||
| 14 | private $encoderTypes; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @param TypeEncoderInterface[] $encoderTypes |
||
| 18 | */ |
||
| 19 | 3 | public function __construct(array $encoderTypes) |
|
| 24 | } |
||
| 25 | 3 | } |
|
| 26 | |||
| 27 | public function getContentTypes(): array |
||
| 28 | { |
||
| 29 | return array_keys($this->encoderTypes); |
||
| 30 | 1 | } |
|
| 31 | |||
| 32 | 1 | /** |
|
| 33 | * @throws SerializerLogicException |
||
| 34 | */ |
||
| 35 | public function encode(array $data, string $contentType): string |
||
| 36 | { |
||
| 37 | if (isset($this->encoderTypes[$contentType])) { |
||
| 38 | return $this->encoderTypes[$contentType]->encode($data); |
||
| 39 | } |
||
| 40 | |||
| 41 | throw SerializerLogicException::createMissingContentType($contentType); |
||
| 42 | } |
||
| 43 | 2 | ||
| 44 | private function addTypeEncoder(TypeEncoderInterface $encoderType): void |
||
| 47 | } |
||
| 48 | } |
||
| 49 |