Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
98.11% |
52 / 53 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ResultFormatter | |
98.11% |
52 / 53 |
|
66.67% |
2 / 3 |
13 | |
0.00% |
0 / 1 |
| getIconName | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| formatForNcSelect | |
100.00% |
31 / 31 |
|
100.00% |
1 / 1 |
8 | |||
| replaceShareTypeWithMethod | |
90.91% |
10 / 11 |
|
0.00% |
0 / 1 |
4.01 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Service\Identify; |
| 10 | |
| 11 | use OCA\Libresign\Collaboration\Collaborators\AccountPhonePlugin; |
| 12 | use OCA\Libresign\Collaboration\Collaborators\ContactPhonePlugin; |
| 13 | use OCA\Libresign\Collaboration\Collaborators\ManualPhonePlugin; |
| 14 | use OCA\Libresign\Collaboration\Collaborators\SignerPlugin; |
| 15 | use OCP\Share\IShare; |
| 16 | |
| 17 | class ResultFormatter { |
| 18 | private function getIconName(string $method): ?string { |
| 19 | return match ($method) { |
| 20 | 'account', |
| 21 | 'email', |
| 22 | 'signal', |
| 23 | 'sms', |
| 24 | 'telegram', |
| 25 | 'whatsapp', |
| 26 | 'xmpp' => $method, |
| 27 | 'whatsappbusiness' => 'whatsapp', |
| 28 | default => null, |
| 29 | }; |
| 30 | } |
| 31 | |
| 32 | public function formatForNcSelect(array $list): array { |
| 33 | $formattedList = []; |
| 34 | foreach ($list as $key => $item) { |
| 35 | $shareType = $item['value']['shareType']; |
| 36 | $method = $item['method'] ?? ''; |
| 37 | |
| 38 | // Determine if this is not a regular user account |
| 39 | $isNoUser = $shareType !== IShare::TYPE_USER; |
| 40 | if ($isNoUser && $method === 'account') { |
| 41 | $isNoUser = false; |
| 42 | } |
| 43 | |
| 44 | $formattedList[$key] = [ |
| 45 | 'identify' => $item['value']['shareWith'], |
| 46 | 'isNoUser' => $isNoUser, |
| 47 | 'displayName' => $item['label'], |
| 48 | 'subname' => $item['shareWithDisplayNameUnique'] ?? '', |
| 49 | ]; |
| 50 | |
| 51 | if ($shareType === IShare::TYPE_EMAIL) { |
| 52 | $formattedList[$key]['method'] = 'email'; |
| 53 | $formattedList[$key]['iconName'] = $this->getIconName('email'); |
| 54 | } elseif ($shareType === IShare::TYPE_USER) { |
| 55 | $formattedList[$key]['method'] = 'account'; |
| 56 | $formattedList[$key]['iconName'] = $this->getIconName('account'); |
| 57 | } elseif (in_array($shareType, [ |
| 58 | SignerPlugin::TYPE_SIGNER, |
| 59 | AccountPhonePlugin::TYPE_SIGNER_ACCOUNT_PHONE, |
| 60 | ContactPhonePlugin::TYPE_SIGNER_CONTACT_PHONE, |
| 61 | ManualPhonePlugin::TYPE_SIGNER_MANUAL_PHONE, |
| 62 | ], true)) { |
| 63 | $method = $item['method'] ?? ''; |
| 64 | $formattedList[$key]['method'] = $method; |
| 65 | $iconName = $this->getIconName($method); |
| 66 | if ($iconName !== null) { |
| 67 | $formattedList[$key]['iconName'] = $iconName; |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | return $formattedList; |
| 72 | } |
| 73 | |
| 74 | public function replaceShareTypeWithMethod(array $list): array { |
| 75 | foreach ($list as $key => $item) { |
| 76 | if (isset($item['method']) && !empty($item['method'])) { |
| 77 | unset($list[$key]['shareType']); |
| 78 | continue; |
| 79 | } |
| 80 | $list[$key]['method'] = match ($item['shareType']) { |
| 81 | IShare::TYPE_EMAIL => 'email', |
| 82 | IShare::TYPE_USER => 'account', |
| 83 | default => '', |
| 84 | }; |
| 85 | unset($list[$key]['shareType']); |
| 86 | } |
| 87 | return $list; |
| 88 | } |
| 89 | } |