GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

LoaResolutionService::hasLoa()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.9332
cc 3
nc 3
nop 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\StepupBundle\Service;
20
21
use LogicException;
22
use Surfnet\StepupBundle\Value\Loa;
23
24
class LoaResolutionService
25
{
26
    /**
27
     * @var \Surfnet\StepupBundle\Value\Loa[]
28
     */
29
    private $loas = [];
30
31
    public function __construct(array $loaDefinitions)
32
    {
33
        foreach ($loaDefinitions as $definition) {
34
            $this->addLoaDefinition($definition);
35
        }
36
    }
37
38
    /**
39
     * @param string $loaIdentifier
40
     * @return bool
41
     */
42
    public function hasLoa($loaIdentifier)
43
    {
44
        foreach ($this->loas as $loa) {
45
            if ($loa->isIdentifiedBy($loaIdentifier)) {
46
                return true;
47
            }
48
        }
49
50
        return false;
51
    }
52
53
    /**
54
     * @param string $loaIdentifier
55
     * @return null|Loa
56
     */
57
    public function getLoa($loaIdentifier)
58
    {
59
        foreach ($this->loas as $loa) {
60
            if ($loa->isIdentifiedBy($loaIdentifier)) {
61
                return $loa;
62
            }
63
        }
64
65
        return null;
66
    }
67
68
    /**
69
     * @param int $loaLevel
70
     * @return null|Loa
71
     */
72
    public function getLoaByLevel($loaLevel)
73
    {
74
        foreach ($this->loas as $loa) {
75
            if ($loa->isOfLevel($loaLevel)) {
76
                return $loa;
77
            }
78
        }
79
80
        return null;
81
    }
82
83
    /**
84
     * @param Loa $loa
85
     */
86
    private function addLoaDefinition(Loa $loa)
87
    {
88
        foreach ($this->loas as $existingLoa) {
89
            if ($existingLoa->equals($loa)) {
90
                throw new LogicException(sprintf(
91
                    'Cannot add Loa "%s" as it has already been added',
92
                    $loa
93
                ));
94
            }
95
        }
96
97
        $this->loas[] = $loa;
98
    }
99
}
100