Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
91.67% |
11 / 12 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| DataPayload | |
91.67% |
11 / 12 |
|
50.00% |
1 / 2 |
11.07 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| assertSerializable | |
90.91% |
10 / 11 |
|
0.00% |
0 / 1 |
10.08 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Service\Notification; |
| 10 | |
| 11 | /** |
| 12 | * Structured transport data for extensions that do not need a built-in |
| 13 | * payload type. Only JSON primitives and arrays may be queued, never |
| 14 | * PHP objects, provider credentials, or authentication codes. |
| 15 | * |
| 16 | * The module interprets its own schema; the dispatcher remains independent. |
| 17 | */ |
| 18 | final readonly class DataPayload implements NotificationPayload { |
| 19 | /** @param array<array-key, mixed> $data */ |
| 20 | public function __construct( |
| 21 | public array $data, |
| 22 | ) { |
| 23 | self::assertSerializable($data, 0); |
| 24 | } |
| 25 | |
| 26 | private static function assertSerializable(mixed $value, int $depth): void { |
| 27 | if ($depth > 8) { |
| 28 | throw new \InvalidArgumentException('Notification payload nesting limit exceeded'); |
| 29 | } |
| 30 | if (is_array($value)) { |
| 31 | foreach ($value as $part) { |
| 32 | self::assertSerializable($part, $depth + 1); |
| 33 | } |
| 34 | return; |
| 35 | } |
| 36 | if ($value === null || is_string($value) || is_int($value) || is_bool($value)) { |
| 37 | return; |
| 38 | } |
| 39 | if (is_float($value) && is_finite($value)) { |
| 40 | return; |
| 41 | } |
| 42 | throw new \InvalidArgumentException('Notification payload must contain only JSON values'); |
| 43 | } |
| 44 | } |