Completed
Pull Request — develop (#92)
by Boy
02:56
created

LoaDomain::findAuthnContextClassRefByLoa()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
3
namespace Surfnet\StepupGateway\GatewayBundle\Entity;
4
5
use Surfnet\StepupBundle\Value\Loa;
6
7
final class LoaDomain
8
{
9
    /**
10
     * @var string
11
     */
12
    private $id;
13
14
    /**
15
     * @var array<string,string>
16
     */
17
    private $loaAuthnContextClassMapping;
18
19
    /**
20
     * @param string $id
21
     * @param array<string,string> $loaAuthnContextClassMapping
22
     */
23
    public function __construct($id, array $loaAuthnContextClassMapping)
24
    {
25
        $this->id = $id;
26
        $this->loaAuthnContextClassMapping = $loaAuthnContextClassMapping;
27
    }
28
29
    /**
30
     * @param string $ref
31
     * @return string|bool
32
     */
33
    public function findLoaIdByAuthnContextClassRef($ref)
34
    {
35
        return array_search($ref, $this->loaAuthnContextClassMapping);
36
    }
37
38
    /**
39
     * @param Loa $loa
40
     * @return string|bool
41
     */
42
    public function findAuthnContextClassRefByLoa(Loa $loa)
43
    {
44
        foreach ($this->loaAuthnContextClassMapping as $loaId => $ref) {
45
            if ($loa->isIdentifiedBy($loaId)) {
46
                return $ref;
47
            }
48
        }
49
        return false;
50
    }
51
}
52