Completed
Push — master ( 5467e4...183ea4 )
by Boy
05:06 queued 01:02
created

SecondFactorIdentifierFactory   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 10
lcom 0
cbo 6
dl 0
loc 53
rs 10
c 3
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
B forType() 0 20 5
B unknownForType() 0 20 5
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\Stepup\Identity\Value;
20
21
use Surfnet\Stepup\Exception\LogicException;
22
use Surfnet\StepupBundle\Value\SecondFactorType;
23
24
final class SecondFactorIdentifierFactory
25
{
26
    /**
27
     * @param SecondFactorType $type
28
     * @param string           $secondFactorIdentifier
29
     * @return SecondFactorIdentifier
30
     */
31
    public static function forType(SecondFactorType $type, $secondFactorIdentifier)
32
    {
33
        if ($type->isSms()) {
34
            return new PhoneNumber($secondFactorIdentifier);
35
        }
36
37
        if ($type->isYubikey()) {
38
            return new YubikeyPublicId($secondFactorIdentifier);
39
        }
40
41
        if ($type->isGssf()) {
42
            return new GssfId($secondFactorIdentifier);
43
        }
44
45
        if ($type->isU2f()) {
46
            return new U2fKeyHandle($secondFactorIdentifier);
47
        }
48
49
        throw new LogicException(sprintf('Unknown second factor type "%s" encountered', $type->getSecondFactorType()));
50
    }
51
52
    /**
53
     * @param SecondFactorType $type
54
     * @return SecondFactorIdentifier
55
     */
56
    public static function unknownForType(SecondFactorType $type)
57
    {
58
        if ($type->isSms()) {
59
            return PhoneNumber::unknown();
60
        }
61
62
        if ($type->isYubikey()) {
63
            return YubikeyPublicId::unknown();
64
        }
65
66
        if ($type->isGssf()) {
67
            return GssfId::unknown();
68
        }
69
70
        if ($type->isU2f()) {
71
            return U2fKeyHandle::unknown();
72
        }
73
74
        throw new LogicException(sprintf('Unknown second factor type "%s" encountered', $type->getSecondFactorType()));
75
    }
76
}
77