Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ShareTypeResolver
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
2 / 2
11
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 resolve
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
1 / 1
10
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\Identify;
10
11use OCA\Libresign\Collaboration\Collaborators\AccountPhonePlugin;
12use OCA\Libresign\Collaboration\Collaborators\ContactPhonePlugin;
13use OCA\Libresign\Collaboration\Collaborators\ManualPhonePlugin;
14use OCA\Libresign\Collaboration\Collaborators\SignerPlugin;
15use OCA\Libresign\Service\IdentifyMethod\Account;
16use OCA\Libresign\Service\IdentifyMethod\Email;
17use OCA\Libresign\Service\IdentifyMethodService;
18use OCP\Share\IShare;
19
20class ShareTypeResolver {
21    public function __construct(
22        private Email $identifyEmailMethod,
23        private Account $identifyAccountMethod,
24    ) {
25    }
26
27    public function resolve(string $method = ''): array {
28        $normalizedMethod = strtolower(trim($method));
29        $isAllMethods = $normalizedMethod === '' || $normalizedMethod === 'all';
30        $includeAccount = $isAllMethods || $normalizedMethod === 'account';
31        $includeEmail = $isAllMethods || $normalizedMethod === 'email';
32        $includePhone = $isAllMethods || in_array($normalizedMethod, IdentifyMethodService::IDENTIFY_PHONE_METHODS, true);
33
34        $shareTypes = [];
35        if ($includeEmail) {
36            $settings = $this->identifyEmailMethod->getSettings();
37            if ($settings['enabled']) {
38                $shareTypes[] = IShare::TYPE_EMAIL;
39            }
40        }
41
42        if ($includeAccount) {
43            $settings = $this->identifyAccountMethod->getSettings();
44            if ($settings['enabled']) {
45                $shareTypes[] = IShare::TYPE_USER;
46            }
47        }
48
49        $shareTypes[] = SignerPlugin::TYPE_SIGNER;
50
51        if ($includePhone) {
52            $shareTypes[] = AccountPhonePlugin::TYPE_SIGNER_ACCOUNT_PHONE;
53            $shareTypes[] = ContactPhonePlugin::TYPE_SIGNER_CONTACT_PHONE;
54            $shareTypes[] = ManualPhonePlugin::TYPE_SIGNER_MANUAL_PHONE;
55        }
56
57        return $shareTypes;
58    }
59}