Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.00% |
9 / 10 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| NotificationTransportRegistry | |
90.00% |
9 / 10 |
|
50.00% |
1 / 2 |
5.03 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| resolve | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
4.02 | |||
| 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 | /** Resolve the same transport in HTTP and background-job processes. */ |
| 12 | final class NotificationTransportRegistry { |
| 13 | public function __construct( |
| 14 | private NotificationModuleCatalog $modules, |
| 15 | ) { |
| 16 | } |
| 17 | |
| 18 | public function resolve(string $channel): NotificationChannel { |
| 19 | $transport = null; |
| 20 | foreach ($this->modules->all() as $module) { |
| 21 | $candidate = $module->transport(); |
| 22 | if (!$candidate->supports($channel)) { |
| 23 | continue; |
| 24 | } |
| 25 | if ($transport !== null) { |
| 26 | throw new \LogicException('Multiple notification modules support the same channel'); |
| 27 | } |
| 28 | $transport = $candidate; |
| 29 | } |
| 30 | return $transport ?? throw new \LogicException('No notification module supports the queued channel'); |
| 31 | } |
| 32 | } |