Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
4 / 8
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ParticipantRole
50.00% covered (danger)
50.00%
4 / 8
66.67% covered (warning)
66.67%
2 / 3
8.12
0.00% covered (danger)
0.00%
0 / 1
 canSign
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLabel
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 fromNullable
100.00% covered (success)
100.00%
3 / 3
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
12use OCP\IL10N;
13
14enum ParticipantRole: string {
15    case SIGNER = 'signer';
16    case OBSERVER = 'observer';
17
18    public function canSign(): bool {
19        return $this === self::SIGNER;
20    }
21
22    public function getLabel(IL10N $l10n): string {
23        return match ($this) {
24            // TRANSLATORS Participant role label for someone who must digitally sign the document.
25            self::SIGNER => $l10n->t('Signer'),
26            // TRANSLATORS Participant role label for someone who can only view the document and track progress.
27            self::OBSERVER => $l10n->t('Observer'),
28        };
29    }
30
31    /**
32     * @throws \ValueError When $value is not empty and is not a known participant role
33     */
34    public static function fromNullable(?string $value): self {
35        if ($value === null || $value === '') {
36            return self::SIGNER;
37        }
38
39        return self::from($value);
40    }
41}