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.
Completed
Pull Request — develop (#32)
by Boy
08:18 queued 05:44
created

Loa::canSatisfyLoa()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
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\Value;
20
21
use Surfnet\StepupBundle\Exception\DomainException;
22
use Surfnet\StepupBundle\Exception\InvalidArgumentException;
23
24
/**
25
 * Value object representing the different LOAs that can be configured
26
 */
27
class Loa
28
{
29
    /**
30
     * The different levels
31
     */
32
    const LOA_1 = 1;
33
    const LOA_2 = 2;
34
    const LOA_3 = 3;
35
36
    /**
37
     * @var int
38
     */
39
    private $level;
40
41
    /**
42
     * @var string
43
     */
44
    private $authnContextClasses;
45
46
    public static function getLevels()
47
    {
48
        return [self::LOA_1, self::LOA_2, self::LOA_3];
49
    }
50
51
    /**
52
     * Loa constructor.
53
     * @param $level
54
     * @param AuthnContextClass[] $authnContextClasses
55
     */
56
    public function __construct($level, array $authnContextClasses)
57
    {
58
        $possibleLevels = static::getLevels();
59
        if (!in_array($level, $possibleLevels, true)) {
60
            throw new DomainException(sprintf(
61
                'Unknown loa level "%s", known levels: "%s"',
62
                is_object($level) ? get_class($level) : $level,
63
                implode('", "', $possibleLevels)
64
            ));
65
        }
66
67
        foreach ($authnContextClasses as $authnContextClass) {
68
            if (!$authnContextClass instanceof AuthnContextClass) {
69
                throw InvalidArgumentException::invalidType(
70
                  '\Surfnet\StepupBundle\Value',
71
                  'authnContextClassRefs',
72
                  $authnContextClass
73
                );
74
            }
75
        }
76
77
        $this->level = $level;
78
        $this->authnContextClasses = $authnContextClasses;
0 ignored issues
show
Documentation Bug introduced by
It seems like $authnContextClasses of type array<integer,object<Sur...lue\AuthnContextClass>> is incompatible with the declared type string of property $authnContextClasses.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
79
    }
80
81
    /**
82
     * @param string $identifier
0 ignored issues
show
Bug introduced by
There is no parameter named $identifier. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
83
     * @return bool
84
     */
85
    public function isIdentifiedBy($authnContextClassRef)
86
    {
87
        foreach ($this->authnContextClasses as $authnContextClass) {
0 ignored issues
show
Bug introduced by
The expression $this->authnContextClasses of type string is not traversable.
Loading history...
88
            if ($authnContextClass->isIdentifiedBy($authnContextClassRef)) {
89
                return true;
90
            }
91
        }
92
        return false;
93
    }
94
95
    /**
96
     * @param string $type
97
     * @return AuthnContextClass
98
     */
99
    public function fetchAuthnContextClassOfType($type)
100
    {
101
        foreach ($this->authnContextClasses as $authnContextClass) {
0 ignored issues
show
Bug introduced by
The expression $this->authnContextClasses of type string is not traversable.
Loading history...
102
            if ($authnContextClass->isOfType($type)) {
103
                return $authnContextClass;
104
            }
105
        }
106
107
        throw new \RuntimeException(
108
          sprintf('No AuthnContextClass of type "%s"', $type)
109
        );
110
    }
111
112
    /**
113
     * @param int $level
114
     * @return bool
115
     */
116
    public function levelIsLowerOrEqualTo($level)
117
    {
118
        return $this->level <= $level;
119
    }
120
121
    /**
122
     * @param int $level
123
     * @return bool
124
     */
125
    public function levelIsHigherOrEqualTo($level)
126
    {
127
        return $this->level >= $level;
128
    }
129
130
    /**
131
     * @param Loa $loa
132
     * @return bool
133
     */
134
    public function canSatisfyLoa(Loa $loa)
135
    {
136
        return $loa->levelIsLowerOrEqualTo($this->level);
137
    }
138
139
    /**
140
     * @param Loa $loa
141
     * @return bool
142
     */
143
    public function equals(Loa $loa)
144
    {
145
        $myClassRefs = [];
146
        foreach ($this->authnContextClasses as $class) {
0 ignored issues
show
Bug introduced by
The expression $this->authnContextClasses of type string is not traversable.
Loading history...
147
            $myClassRefs[] = (string) $class;
148
        }
149
        $theirClassRefs = [];
150
        foreach ($loa->authnContextClasses as $class) {
0 ignored issues
show
Bug introduced by
The expression $loa->authnContextClasses of type string is not traversable.
Loading history...
151
            $theirClassRefs[] = (string) $class;
152
        }
153
        return $this->level === $loa->level
154
            && empty(array_diff($myClassRefs, $theirClassRefs))
155
            && empty(array_diff($theirClassRefs, $myClassRefs));
156
    }
157
158
    /**
159
     * @param int $loaLevel
160
     * @return bool
161
     */
162
    public function isOfLevel($loaLevel)
163
    {
164
        return $this->level === $loaLevel;
165
    }
166
167
    public function __toString()
168
    {
169
        return (string) $this->level;
170
    }
171
}
172