Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ObserverProfilePolicyValue
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 normalize
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSnapshotEffectiveValue
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
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\ObserverProfile;
10
11use OCA\Libresign\Db\File as FileEntity;
12
13final class ObserverProfilePolicyValue {
14    public static function normalize(mixed $value): bool {
15        return filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ?? false;
16    }
17
18    public static function getSnapshotEffectiveValue(FileEntity $file): ?bool {
19        $metadata = $file->getMetadata() ?? [];
20        $policySnapshot = $metadata['policy_snapshot'] ?? null;
21        if (!is_array($policySnapshot)) {
22            return null;
23        }
24
25        $entry = $policySnapshot[ObserverProfilePolicy::KEY] ?? null;
26        if (!is_array($entry) || !array_key_exists('effectiveValue', $entry)) {
27            return null;
28        }
29
30        return self::normalize($entry['effectiveValue']);
31    }
32}