Lines 100.00% 17 / 17
Methods 100.00% 3 / 3
Classes 100.00% 1 / 1
Covered by tests of size
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 toArray 100.00% 6 / 6 100.00% 1 / 1 1
 fromArray 100.00% 10 / 10 100.00% 1 / 1 3
22final readonly class SendMailMessage implements QueueMessageInterface
23{
24    /**
25     * @param array<string, mixed> $metadata
26     */
27    public function __construct(
28        public string $recipient,
29        public string $subject,
30        public string $body,
31        public array $metadata = [],
32    ) {
33    }
34
35    public function toArray(): array
36    {
37        return [
38            'recipient' => $this->recipient,
39            'subject' => $this->subject,
40            'body' => $this->body,
41            'metadata' => $this->metadata,
42        ];
43    }
44
45    public static function fromArray(array $payload): self
46    {
47        $rawMetadata = is_array($payload['metadata'] ?? null) ? $payload['metadata'] : [];
48        $metadata = [];
49        foreach ($rawMetadata as $metadataKey => $metadataValue) {
50            $metadata[(string) $metadataKey] = $metadataValue;
51        }
52
53        return new self(
54            recipient: (string) ($payload['recipient'] ?? ''),
55            subject: (string) ($payload['subject'] ?? ''),
56            body: (string) ($payload['body'] ?? ''),
57            metadata: $metadata,
58        );
59    }
60}