| Conditions | 9 |
| Paths | 4 |
| Total Lines | 27 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 9 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 29 | 11 | public function unserialize(string $value): MessageInterface |
|
| 30 | { |
||
| 31 | 11 | $payload = json_decode($value, true, 512, JSON_THROW_ON_ERROR); |
|
| 32 | 11 | if (!is_array($payload)) { |
|
| 33 | 4 | throw new InvalidArgumentException('Payload must be array. Got ' . get_debug_type($payload) . '.'); |
|
| 34 | } |
||
| 35 | |||
| 36 | 7 | $meta = $payload['meta'] ?? []; |
|
| 37 | 7 | if (!is_array($meta)) { |
|
| 38 | 3 | throw new InvalidArgumentException('Metadata must be array. Got ' . get_debug_type($meta) . '.'); |
|
| 39 | } |
||
| 40 | |||
| 41 | 4 | $message = new Message($payload['data'] ?? null, $meta); |
|
| 42 | |||
| 43 | 4 | if (isset($meta[EnvelopeInterface::ENVELOPE_STACK_KEY]) && is_array($meta[EnvelopeInterface::ENVELOPE_STACK_KEY])) { |
|
| 44 | 2 | $message = $message->withMetadata( |
|
| 45 | 2 | array_merge($message->getMetadata(), [EnvelopeInterface::ENVELOPE_STACK_KEY => []]), |
|
| 46 | 2 | ); |
|
| 47 | 2 | foreach ($meta[EnvelopeInterface::ENVELOPE_STACK_KEY] as $envelope) { |
|
| 48 | 2 | if (is_string($envelope) && class_exists($envelope) && is_subclass_of($envelope, EnvelopeInterface::class)) { |
|
| 49 | 2 | $message = $envelope::fromMessage($message); |
|
| 50 | } |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | |||
| 55 | 4 | return $message; |
|
| 56 | } |
||
| 58 |