Lines 100.00% 15 / 15
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% 5 / 5 100.00% 1 / 1 1
 fromArray 100.00% 9 / 9 100.00% 1 / 1 3
22final readonly class ExportMessage implements QueueMessageInterface
23{
24    /**
25     * @param array<string, mixed> $options
26     */
27    public function __construct(
28        public string $format,
29        public int $userId,
30        public array $options = [],
31    ) {
32    }
33
34    public function toArray(): array
35    {
36        return [
37            'format' => $this->format,
38            'userId' => $this->userId,
39            'options' => $this->options,
40        ];
41    }
42
43    public static function fromArray(array $payload): self
44    {
45        $rawOptions = is_array($payload['options'] ?? null) ? $payload['options'] : [];
46        $options = [];
47        foreach ($rawOptions as $optionKey => $optionValue) {
48            $options[(string) $optionKey] = $optionValue;
49        }
50
51        return new self(
52            format: (string) ($payload['format'] ?? ''),
53            userId: (int) ($payload['userId'] ?? 0),
54            options: $options,
55        );
56    }
57}