Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
30 / 30 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ManualPhonePlugin | |
100.00% |
30 / 30 |
|
100.00% |
2 / 2 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| search | |
100.00% |
29 / 29 |
|
100.00% |
1 / 1 |
6 | |||
| 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\Collaboration\Collaborators; |
| 10 | |
| 11 | use OCA\Libresign\Service\Identify\SignerSearchContext; |
| 12 | use OCA\Libresign\Service\IdentifyMethodService; |
| 13 | use OCP\Collaboration\Collaborators\ISearchPlugin; |
| 14 | use OCP\Collaboration\Collaborators\ISearchResult; |
| 15 | use OCP\Collaboration\Collaborators\SearchResultType; |
| 16 | use OCP\IConfig; |
| 17 | use OCP\IPhoneNumberUtil; |
| 18 | |
| 19 | class ManualPhonePlugin implements ISearchPlugin { |
| 20 | public const TYPE_SIGNER_MANUAL_PHONE = 53; |
| 21 | |
| 22 | public function __construct( |
| 23 | private IConfig $config, |
| 24 | private IPhoneNumberUtil $phoneNumberUtil, |
| 25 | private SignerSearchContext $searchContext, |
| 26 | ) { |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * {@inheritdoc} |
| 31 | */ |
| 32 | #[\Override] |
| 33 | public function search($search, $limit, $offset, ISearchResult $searchResult): bool { |
| 34 | $method = $this->searchContext->getMethod(); |
| 35 | $search = trim((string)$search); |
| 36 | |
| 37 | if ($search === '' || !in_array($method, IdentifyMethodService::IDENTIFY_PHONE_METHODS, true)) { |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | $rawSearch = trim($this->searchContext->getRawSearch()); |
| 42 | if ($rawSearch === '') { |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | $defaultRegion = $this->config->getSystemValueString('default_phone_region', ''); |
| 47 | $standardFormat = $this->phoneNumberUtil->convertToStandardFormat( |
| 48 | $rawSearch, |
| 49 | $defaultRegion !== '' ? $defaultRegion : null, |
| 50 | ); |
| 51 | if ($standardFormat === null) { |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | $result = [ |
| 56 | 'exact' => [[ |
| 57 | 'label' => $search, |
| 58 | 'shareWithDisplayNameUnique' => $search, |
| 59 | 'method' => $method, |
| 60 | 'value' => [ |
| 61 | 'shareWith' => $search, |
| 62 | 'shareType' => self::TYPE_SIGNER_MANUAL_PHONE, |
| 63 | ], |
| 64 | ]], |
| 65 | 'wide' => [], |
| 66 | ]; |
| 67 | |
| 68 | $type = new SearchResultType('manual-phone'); |
| 69 | $searchResult->addResultSet($type, $result['wide'], $result['exact']); |
| 70 | |
| 71 | return false; |
| 72 | } |
| 73 | } |