Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.86% |
13 / 14 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| SignerIndexProvider | |
92.86% |
13 / 14 |
|
50.00% |
1 / 2 |
6.01 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| build | |
92.31% |
12 / 13 |
|
0.00% |
0 / 1 |
5.01 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Service; |
| 10 | |
| 11 | use OCA\Libresign\Db\SignRequest; |
| 12 | |
| 13 | class SignerIndexProvider { |
| 14 | public function __construct( |
| 15 | private IdentifyMethodService $identifyMethodService, |
| 16 | ) { |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * @param SignRequest[] $signRequests |
| 21 | * @return array<string, SignRequest[]> |
| 22 | */ |
| 23 | public function build(array $signRequests): array { |
| 24 | if (empty($signRequests)) { |
| 25 | return []; |
| 26 | } |
| 27 | $signRequestIds = array_column(array_map(fn ($sr) => ['id' => $sr->getId()], $signRequests), 'id'); |
| 28 | $identifyMethodsBatch = $this->identifyMethodService->getIdentifyMethodsFromSignRequestIds($signRequestIds); |
| 29 | |
| 30 | $index = []; |
| 31 | foreach ($signRequests as $signRequest) { |
| 32 | $identifyMethods = $identifyMethodsBatch[$signRequest->getId()] ?? []; |
| 33 | foreach ($identifyMethods as $methodInstances) { |
| 34 | foreach ($methodInstances as $identifyMethod) { |
| 35 | $entity = $identifyMethod->getEntity(); |
| 36 | $indexKey = $entity->getIdentifierKey() . ':' . $entity->getIdentifierValue(); |
| 37 | $index[$indexKey][] = $signRequest; |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | return $index; |
| 42 | } |
| 43 | } |