| Total Complexity | 5 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | class InternalCryptoSerializer extends BaseSerializer |
||
| 13 | { |
||
| 14 | private CryptographyService $crypto; |
||
| 15 | |||
| 16 | 3 | public function __construct( |
|
| 17 | CryptographyService $crypto, |
||
| 18 | ?Serializer $serializer = null, |
||
| 19 | string $format = 'json', |
||
| 20 | array $context = [] |
||
| 21 | ) { |
||
| 22 | 3 | parent::__construct($serializer, $format, $context); |
|
| 23 | 3 | $this->crypto = $crypto; |
|
| 24 | } |
||
| 25 | |||
| 26 | 2 | public function decode(array $encodedEnvelope): Envelope |
|
| 27 | { |
||
| 28 | 2 | return parent::decode([ |
|
| 29 | 2 | 'body' => $this->crypto->decrypt(self::getBody($encodedEnvelope)), |
|
| 30 | 2 | 'headers' => self::getHeaders($encodedEnvelope), |
|
| 31 | 2 | ]); |
|
| 32 | } |
||
| 33 | |||
| 34 | 2 | public function encode(Envelope $envelope): array |
|
| 35 | { |
||
| 36 | 2 | $encodedEnvelope = parent::encode($envelope); |
|
| 37 | |||
| 38 | 2 | return [ |
|
| 39 | 2 | 'body' => $this->crypto->encrypt(self::getBody($encodedEnvelope)), |
|
| 40 | 2 | 'headers' => self::getHeaders($encodedEnvelope), |
|
| 41 | 2 | ]; |
|
| 42 | } |
||
| 43 | |||
| 44 | 3 | private static function getBody(array $decodedEnvelope): ?string |
|
| 47 | } |
||
| 48 | |||
| 49 | 3 | protected static function getHeaders(array $decodedEnvelope): array |
|
| 52 | } |
||
| 53 | } |
||
| 54 |