Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
89.47% |
17 / 19 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| MailChannel | |
89.47% |
17 / 19 |
|
66.67% |
2 / 3 |
9.09 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| supports | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| deliver | |
88.24% |
15 / 17 |
|
0.00% |
0 / 1 |
7.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 | use OCA\Libresign\Service\MailService; |
| 12 | |
| 13 | final class MailChannel implements NotificationChannel { |
| 14 | public function __construct( |
| 15 | private MailService $mail, |
| 16 | ) { |
| 17 | } |
| 18 | |
| 19 | #[\Override] |
| 20 | public function supports(string $channel): bool { |
| 21 | return $channel === 'mail'; |
| 22 | } |
| 23 | |
| 24 | #[\Override] |
| 25 | public function deliver(NotificationMessage $message): void { |
| 26 | if (!$message->payload instanceof MailPayload) { |
| 27 | throw new \InvalidArgumentException('Invalid mail notification payload'); |
| 28 | } |
| 29 | $signRequest = $message->signRequest; |
| 30 | $email = $message->recipient; |
| 31 | switch ($message->eventType) { |
| 32 | case 'sign_request': |
| 33 | if ($message->payload->firstNotification) { |
| 34 | $this->mail->notifyUnsignedUser($signRequest, $email, $signRequest->getDescription()); |
| 35 | } else { |
| 36 | $this->mail->notifySignDataUpdated($signRequest, $email, $signRequest->getDescription()); |
| 37 | } |
| 38 | break; |
| 39 | case 'file_signed': |
| 40 | $this->mail->notifySignedUser($signRequest, $email, $message->file, $message->payload->displayName ?? ''); |
| 41 | break; |
| 42 | case 'sign_request_canceled': |
| 43 | $this->mail->notifyCanceledRequest($signRequest, $email, $message->file); |
| 44 | break; |
| 45 | default: |
| 46 | throw new \InvalidArgumentException('Unsupported mail notification event'); |
| 47 | } |
| 48 | } |
| 49 | } |