Completed
Push — feature/authz-service ( 7efef2...42019b )
by
unknown
03:56
created

couldInstitutionUseRaFor()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
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\StepupMiddleware\ApiBundle\Configuration\Entity\InstitutionAuthorization;
23
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Repository\InstitutionAuthorizationRepository;
24
25
class InstitutionAuthorizationService
26
{
27
    /**
28
     * @var InstitutionAuthorizationRepository
29
     */
30
    private $repository;
31
32
    /**
33
     * @param InstitutionAuthorizationRepository $repository
34
     */
35
    public function __construct(
36
        InstitutionAuthorizationRepository $repository
37
    ) {
38
        $this->repository = $repository;
39
    }
40
41
    /**
42
     * @param Institution $institution
43
     * @param Institution $for
44
     * @return bool
45
     */
46
    public function couldInstitutionUseRaFor(Institution $institution, Institution $for)
47
    {
48
        $authorization = $this->findAuthorizationFor($institution);
49
        return $authorization->useRaOption->hasOptions() && $authorization->useRaOption->isOption($for->getInstitution());
50
    }
51
52
    /**
53
     * @param Institution $institution
54
     * @param Institution $for
55
     * @return bool
56
     */
57
    public function couldInstitutionUseRaaFor(Institution $institution, Institution $for)
58
    {
59
        $authorization = $this->findAuthorizationFor($institution);
60
        return $authorization->useRaaOption->hasOptions() && $authorization->useRaaOption->isOption($for->getInstitution());
61
    }
62
63
    /**
64
     * @param Institution $institution
65
     * @param Institution $for
66
     * @return bool
67
     */
68
    public function couldInstitutionSelectRaaFor(Institution $institution, Institution $for)
69
    {
70
        $authorization = $this->findAuthorizationFor($institution);
71
        return $authorization->selectRaaOption->hasOptions() && $authorization->selectRaaOption->isOption($for->getInstitution());
72
    }
73
74
75
    /**
76
     * @param Institution $institution
77
     * @return InstitutionAuthorization
78
     */
79
    private function findAuthorizationFor(Institution $institution)
80
    {
81
        return $this->repository->findAuthorizationForInstitution($institution);
82
    }
83
84
}
85