Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
15 / 18
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
NotificationDeliveryModePolicy
83.33% covered (warning)
83.33%
15 / 18
0.00% covered (danger)
0.00%
0 / 2
4.07
0.00% covered (danger)
0.00%
0 / 1
 keys
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get
88.24% covered (warning)
88.24%
15 / 17
0.00% covered (danger)
0.00%
0 / 1
3.01
1<?php
2
3declare(strict_types=1);
4/**
5 * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
6 * SPDX-License-Identifier: AGPL-3.0-or-later
7 */
8
9namespace OCA\Libresign\Service\Policy\Provider\NotificationDelivery;
10
11use OCA\Libresign\Service\Policy\Contract\IPolicyDefinition;
12use OCA\Libresign\Service\Policy\Contract\IPolicyDefinitionProvider;
13use OCA\Libresign\Service\Policy\Model\PolicySpec;
14use OCA\Libresign\Service\Policy\Provider\Helper\PolicyKeyNormalizer;
15
16/** Delivery defaults to synchronous mode; async must be enabled explicitly. */
17final class NotificationDeliveryModePolicy implements IPolicyDefinitionProvider {
18    public const KEY = 'notification_delivery_mode';
19    public const MODE_SYNC = 'sync';
20    public const MODE_ASYNC = 'async';
21
22    #[\Override]
23    public function keys(): array {
24        return [self::KEY];
25    }
26
27    #[\Override]
28    public function get(string|\BackedEnum $policyKey): IPolicyDefinition {
29        if (PolicyKeyNormalizer::normalize($policyKey) !== self::KEY) {
30            throw new \InvalidArgumentException('Unknown policy key: ' . PolicyKeyNormalizer::normalize($policyKey));
31        }
32
33        return new PolicySpec(
34            key: self::KEY,
35            defaultSystemValue: self::MODE_SYNC,
36            allowedValues: [self::MODE_SYNC, self::MODE_ASYNC],
37            normalizer: static fn (mixed $raw): string => strtolower(trim((string)$raw)),
38            validator: static function (mixed $value): void {
39                if (!in_array($value, [self::MODE_SYNC, self::MODE_ASYNC], true)) {
40                    throw new \InvalidArgumentException('Invalid notification delivery mode');
41                }
42            },
43            appConfigKey: self::KEY,
44            supportsUserPreference: false,
45            supportsRequestOverride: false,
46            requestLifecycle: PolicySpec::LIFECYCLE_RUNTIME,
47            supportedScopes: [PolicySpec::SCOPE_SYSTEM],
48        );
49    }
50}