RaCandidateService   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 44
rs 10
c 1
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A setUseRaInstitutionsOnRaCandidate() 0 8 2
A findOneByIdentityId() 0 3 1
A search() 0 5 1
A getFilterOptions() 0 3 1
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupMiddleware\ApiBundle\Identity\Service;
20
21
use Pagerfanta\Pagerfanta;
22
use Surfnet\Stepup\Identity\Value\Institution;
23
use Surfnet\StepupMiddleware\ApiBundle\Authorization\Value\InstitutionAuthorizationContext;
24
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\RaCandidate;
25
use Surfnet\StepupMiddleware\ApiBundle\Identity\Query\RaCandidateQuery;
26
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\RaCandidateRepository;
27
28
/** @extends AbstractSearchService<RaCandidate> */
29
class RaCandidateService extends AbstractSearchService
30
{
31
    public function __construct(private readonly RaCandidateRepository $raCandidateRepository)
32
    {
33
    }
34
35
    /**
36
     * @return Pagerfanta<RaCandidate>
37
     */
38
    public function search(RaCandidateQuery $query): Pagerfanta
39
    {
40
        $doctrineQuery = $this->raCandidateRepository->createSearchQuery($query);
41
42
        return $this->createPaginatorFrom($doctrineQuery, $query, false);
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function getFilterOptions(RaCandidateQuery $query): array
49
    {
50
        return $this->getFilteredQueryOptions($this->raCandidateRepository->createOptionsQuery($query));
51
    }
52
53
    /**
54
     * @return null|array
55
     */
56
    public function findOneByIdentityId(string $identityId): ?array
57
    {
58
        return $this->raCandidateRepository->findOneByIdentityId($identityId);
59
    }
60
61
    /**
62
     * Set the RA candidates USE RA(A) institutions on the Identity he is going to promote.
63
     * @return non-empty-array[]
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-array[] at position 0 could not be parsed: Unknown type name 'non-empty-array' at position 0 in non-empty-array[].
Loading history...
64
     */
65
    public function setUseRaInstitutionsOnRaCandidate(InstitutionAuthorizationContext $actor, array $raCandidate): array
66
    {
67
        $result = [];
68
        foreach ($actor->getInstitutions() as $raInstitution) {
69
            $raCandidate['ra_institution'] = new Institution($raInstitution->getInstitution());
70
            $result[] = $raCandidate;
71
        }
72
        return $result;
73
    }
74
}
75