U2fKeyHandle   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A equals() 0 3 2
A unknown() 0 3 1
A __construct() 0 12 4
A getValue() 0 3 1
A __toString() 0 3 1
A jsonSerialize() 0 3 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\Stepup\Identity\Value;
20
21
use Surfnet\Stepup\Exception\InvalidArgumentException;
22
23
/**
24
 * @deprecated Built in U2F support is dropped from StepUp, this was not removed to support event replay
25
 */
26
final class U2fKeyHandle implements SecondFactorIdentifier
27
{
28
    public const UNKNOWN = '—';
29
30
    private string $value;
31
32
    /**
33
     * @return static
34
     */
35
    public static function unknown(): static
36
    {
37
        return new self(self::UNKNOWN);
38
    }
39
40
    public function __construct(string $value)
41
    {
42
        if ($value === self::UNKNOWN) {
43
            $this->value = $value;
44
            return;
45
        }
46
47
        if ($value === '' || $value === '0') {
48
            throw new InvalidArgumentException('Invalid Argument, parameter "value" may not be an empty string');
49
        }
50
51
        $this->value = $value;
52
    }
53
54
    public function getValue(): string
55
    {
56
        return $this->value;
57
    }
58
59
    public function __toString(): string
60
    {
61
        return $this->value;
62
    }
63
64
    public function equals(SecondFactorIdentifier $other): bool
65
    {
66
        return $other instanceof self && $this->value === $other->value;
67
    }
68
69
    public function jsonSerialize(): string
70
    {
71
        return $this->value;
72
    }
73
}
74