Completed
Pull Request — develop (#93)
by Boy
03:04
created

LoaAliasLookupService   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 9
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 62
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 21 4
A findLoaIdByAlias() 0 11 2
A findAliasByLoa() 0 9 3
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\StepupGateway\SecondFactorOnlyBundle\Service;
20
21
use Surfnet\StepupBundle\Value\Loa;
22
use Surfnet\StepupGateway\GatewayBundle\Exception\InvalidArgumentException;
23
24
final class LoaAliasLookupService
25
{
26
    /**
27
     * @var array<string,string>
28
     */
29
    private $loaAliases;
30
31
    /**
32
     * @param array<string,string> $loaAuthnContextClassMapping
0 ignored issues
show
Bug introduced by
There is no parameter named $loaAuthnContextClassMapping. 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...
33
     */
34
    public function __construct(array $loaAliases)
35
    {
36
        foreach ($loaAliases as $loaId => $alias) {
37
            if (!is_string($loaId)) {
38
                throw InvalidArgumentException::invalidType(
39
                    'string',
40
                    'authnContextClassRef',
41
                    $alias
42
                );
43
            }
44
            if (!is_string($alias)) {
45
                throw InvalidArgumentException::invalidType(
46
                    'string',
47
                    'alias',
48
                    $alias
49
                );
50
            }
51
        }
52
53
        $this->loaAliases = $loaAliases;
54
    }
55
56
    /**
57
     * @param string $alias
58
     * @return string|bool
59
     */
60
    public function findLoaIdByAlias($alias)
61
    {
62
        if (!is_string($alias)) {
63
            throw InvalidArgumentException::invalidType(
64
                'string',
65
                'alias',
66
                $alias
67
            );
68
        }
69
        return array_search($alias, $this->loaAliases);
70
    }
71
72
    /**
73
     * @param Loa $loa
74
     * @return string|bool
75
     */
76
    public function findAliasByLoa(Loa $loa)
77
    {
78
        foreach ($this->loaAliases as $loaId => $alias) {
79
            if ($loa->isIdentifiedBy($loaId)) {
80
                return $alias;
81
            }
82
        }
83
        return false;
84
    }
85
}
86