Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
SignatureRejectionVisibility
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
4 / 4
7
100.00% covered (success)
100.00%
1 / 1
 level
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 covers
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 narrowest
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 tryFromValue
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5/**
6 * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
7 * SPDX-License-Identifier: AGPL-3.0-or-later
8 */
9
10namespace OCA\Libresign\Enum;
11
12/**
13 * The widest audience that may learn about a rejection.
14 *
15 * The levels are cumulative: every audience also contains the ones below it,
16 * so `public` includes the participants and the requester. The requester and
17 * the signer who rejected always see their own record, whatever the level is.
18 */
19enum SignatureRejectionVisibility: string {
20    /** Only the requester, plus the rejecting signer on their own entry. */
21    case REQUESTER = 'requester';
22    /** Also the signers taking part in the workflow. */
23    case PARTICIPANTS = 'participants';
24    /** Also the public validation responses. */
25    case PUBLIC = 'public';
26
27    /**
28     * Position in the hierarchy. Only meaningful when comparing two levels: the
29     * numbers themselves are not stored anywhere.
30     */
31    public function level(): int {
32        return match ($this) {
33            self::REQUESTER => 0,
34            self::PARTICIPANTS => 1,
35            self::PUBLIC => 2,
36        };
37    }
38
39    /** True when this level reaches at least as far as $other. */
40    public function covers(self $other): bool {
41        return $this->level() >= $other->level();
42    }
43
44    /** The narrower of the two levels. */
45    public function narrowest(self $other): self {
46        return $this->covers($other) ? $other : $this;
47    }
48
49    public static function tryFromValue(mixed $rawValue, self $fallback): self {
50        if ($rawValue instanceof self) {
51            return $rawValue;
52        }
53
54        return is_string($rawValue)
55            ? self::tryFrom(trim($rawValue)) ?? $fallback
56            : $fallback;
57    }
58}