Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
16 / 16 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| SignerPresentation | |
100.00% |
16 / 16 |
|
100.00% |
3 / 3 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| applyTo | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
| applyToObject | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 7 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | */ |
| 9 | |
| 10 | namespace OCA\Libresign\Service\SignatureRejection; |
| 11 | |
| 12 | use OCA\Libresign\Enum\SignerDisplayStatus; |
| 13 | |
| 14 | /** |
| 15 | * Viewer-specific presentation of one signer, built while preparing a |
| 16 | * response and never stored: the real status is null when the viewer may |
| 17 | * not know it. |
| 18 | */ |
| 19 | final class SignerPresentation { |
| 20 | /** |
| 21 | * @param array{rejectedAt: string, comment?: string, commentPrivate?: bool}|null $rejection |
| 22 | */ |
| 23 | public function __construct( |
| 24 | public readonly SignerDisplayStatus $displayStatus, |
| 25 | public readonly ?int $status, |
| 26 | public readonly string $statusText, |
| 27 | public readonly ?array $rejection, |
| 28 | ) { |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Write the presentation into a signer array, removing what must not |
| 33 | * be disclosed. |
| 34 | * |
| 35 | * @param array<string, mixed> $signer |
| 36 | * @return array<string, mixed> |
| 37 | */ |
| 38 | public function applyTo(array $signer): array { |
| 39 | unset($signer['status'], $signer['rejection']); |
| 40 | $signer['displayStatus'] = $this->displayStatus->value; |
| 41 | $signer['statusText'] = $this->statusText; |
| 42 | if ($this->status !== null) { |
| 43 | $signer['status'] = $this->status; |
| 44 | } |
| 45 | if ($this->rejection !== null) { |
| 46 | $signer['rejection'] = $this->rejection; |
| 47 | } |
| 48 | return $signer; |
| 49 | } |
| 50 | |
| 51 | public function applyToObject(\stdClass $signer): void { |
| 52 | unset($signer->status, $signer->rejection); |
| 53 | $signer->displayStatus = $this->displayStatus->value; |
| 54 | $signer->statusText = $this->statusText; |
| 55 | if ($this->status !== null) { |
| 56 | $signer->status = $this->status; |
| 57 | } |
| 58 | if ($this->rejection !== null) { |
| 59 | $signer->rejection = $this->rejection; |
| 60 | } |
| 61 | } |
| 62 | } |