Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
83.33% |
5 / 6 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| GatewayChannel | |
83.33% |
5 / 6 |
|
66.67% |
2 / 3 |
6.17 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| supports | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| deliver | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
3.14 | |||
| 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\TwofactorGatewayService; |
| 12 | |
| 13 | /** Only transmit a pre-composed message to a selected gateway. */ |
| 14 | final class GatewayChannel implements NotificationChannel { |
| 15 | public function __construct( |
| 16 | private TwofactorGatewayService $gateway, |
| 17 | ) { |
| 18 | } |
| 19 | |
| 20 | #[\Override] |
| 21 | public function supports(string $channel): bool { |
| 22 | return str_starts_with($channel, 'gateway:') && strlen($channel) > strlen('gateway:'); |
| 23 | } |
| 24 | |
| 25 | #[\Override] |
| 26 | public function deliver(NotificationMessage $message): void { |
| 27 | $payload = $message->payload; |
| 28 | if (!$payload instanceof GatewayPayload || 'gateway:' . $payload->gatewayName !== $message->channel) { |
| 29 | throw new \InvalidArgumentException('Invalid gateway notification payload'); |
| 30 | } |
| 31 | $this->gateway->send($payload->gatewayName, $message->recipient, $payload->body, $payload->extra); |
| 32 | } |
| 33 | } |