Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| ExportMessage | |
100.00% |
15 / 15 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
| __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 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Message for queued exports. |
| 5 | * |
| 6 | * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 7 | * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 8 | * obtain one at https://mozilla.org/MPL/2.0/. |
| 9 | * |
| 10 | * @package phpMyFAQ |
| 11 | * @author Thorsten Rinne <thorsten@phpmyfaq.de> |
| 12 | * @copyright 2026 phpMyFAQ Team |
| 13 | * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
| 14 | * @link https://www.phpmyfaq.de |
| 15 | * @since 2026-02-11 |
| 16 | */ |
| 17 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace phpMyFAQ\Queue\Message; |
| 21 | |
| 22 | final 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 | } |