Completed
Pull Request — feature/fine-grained-authoriza... (#246)
by
unknown
40:56 queued 21:52
created

findSelectRaaInstitutionsFor()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
rs 9.9
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * Copyright 2018 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\Identity\Value\Institution as ValueInstitution;
23
use Surfnet\Stepup\Configuration\Value\InstitutionAuthorizationOption;
24
use Surfnet\Stepup\Configuration\Value\InstitutionRole;
25
use Surfnet\Stepup\Identity\Collection\InstitutionCollection;
26
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Repository\InstitutionAuthorizationRepository;
27
28
class InstitutionAuthorizationService
29
{
30
    /**
31
     * @var InstitutionAuthorizationRepository
32
     */
33
    private $repository;
34
35
    /**
36
     * @param InstitutionAuthorizationRepository $repository
37
     */
38
    public function __construct(
39
        InstitutionAuthorizationRepository $repository
40
    ) {
41
        $this->repository = $repository;
42
    }
43
44
    /**
45
     * @param Institution $institution
46
     * @param InstitutionRole $role
47
     * @return InstitutionAuthorizationOption
48
     */
49
    public function findAuthorizationsByRoleFor(Institution $institution, InstitutionRole $role)
50
    {
51
        $authorizations = $this->repository->findAuthorizationOptionsForInstitutionByRole($institution, $role);
52
53
        $institutions = [];
54
        foreach ($authorizations as $authorization) {
55
            $institutions[] = $authorization->institutionRelation;
56
        }
57
58
        return InstitutionAuthorizationOption::fromInstitutions($role, $institution, $institutions);
59
    }
60
61
    /**
62
     * @param Institution $institution
63
     * @return InstitutionAuthorizationOptionMap
64
     */
65
    public function findAuthorizationsFor(Institution $institution)
66
    {
67
        $authorizations = $this->repository->findAuthorizationOptionsForInstitution($institution);
68
69
        return InstitutionAuthorizationOptionMap::fromInstitutionAuthorizations($institution, $authorizations);
70
    }
71
72
73
    /**
74
     * @param Institution $institution
75
     * @return InstitutionCollection
76
     */
77
    public function findSelectRaaInstitutionsFor(Institution $institution)
78
    {
79
        $authorizations = $this->repository->findSelectRaasForInstitution($institution, InstitutionRole::selectRaa());
80
81
        $institutions = new InstitutionCollection();
82
        foreach ($authorizations as $authorization) {
83
            $institutions[] = $institutions->add(new ValueInstitution($authorization->institution->getInstitution()));
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $institutions[] is correct as $institutions->add(new \...ion->getInstitution())) (which targets Surfnet\Stepup\Identity\...tutionCollection::add()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
84
        }
85
86
        return $institutions;
87
    }
88
89
90
}
91