Completed
Push — feature/authz-service ( 007e40...3c7a6c )
by
unknown
02:53
created

findAuthorizationsFor()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
/**
4
 * Copyright 2016 SURFnet B.V.
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\Configuration\Service;
20
21
use Surfnet\Stepup\Configuration\Value\Institution;
22
use Surfnet\Stepup\Configuration\Value\InstitutionOption;
23
use Surfnet\Stepup\Configuration\Value\InstitutionRole;
24
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Entity\InstitutionAuthorization;
25
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Repository\InstitutionAuthorizationRepository;
26
27
class InstitutionAuthorizationService
28
{
29
    /**
30
     * @var InstitutionAuthorizationRepository
31
     */
32
    private $repository;
33
34
    /**
35
     * @param InstitutionAuthorizationRepository $repository
36
     */
37
    public function __construct(
38
        InstitutionAuthorizationRepository $repository
39
    ) {
40
        $this->repository = $repository;
41
    }
42
43
    /**
44
     * @param Institution $institution
45
     * @param InstitutionRole $role
46
     * @return InstitutionOption
47
     */
48
    public function findAuthorizationsFor(Institution $institution, InstitutionRole $role)
49
    {
50
        $authorizations = $this->repository->findAuthorizationOptionsForInstitution($institution, $role);
51
52
        $institutions = [];
53
        foreach ($authorizations as $authorization) {
54
            $institutions[] = $authorization->institutionRelation;
55
        }
56
57
        return InstitutionOption::fromInstitutions($role, $institutions);
58
    }
59
}
60