AbstractExtensionInput   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 45
ccs 14
cts 14
cp 1
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __serialize() 0 3 1
A __unserialize() 0 4 1
A getIdentifier() 0 3 1
A getInput() 0 3 1
A __construct() 0 6 2
1
<?php
2
3
namespace MadWizard\WebAuthn\Extension;
4
5
use MadWizard\WebAuthn\Exception\WebAuthnException;
6
use MadWizard\WebAuthn\Format\SerializableTrait;
7
use function sprintf;
8
9
abstract class AbstractExtensionInput implements ExtensionInputInterface
10
{
11
    use SerializableTrait;
12
13
    /**
14
     * @var string
15
     */
16
    private $identifier;
17
18
    /**
19
     * @var mixed // TODO stricter type?
20
     */
21
    protected $input;
22
23 7
    public function __construct(string $identifier)
24
    {
25 7
        $this->identifier = $identifier;
26
27 7
        if (!ExtensionHelper::validExtensionIdentifier($identifier)) {
28 1
            throw new WebAuthnException(sprintf("Invalid extension identifier '%s'.", $identifier));
29
        }
30 6
    }
31
32 3
    public function getIdentifier(): string
33
    {
34 3
        return $this->identifier;
35
    }
36
37
    /**
38
     * @return mixed
39
     */
40 4
    public function getInput()
41
    {
42 4
        return $this->input;
43
    }
44
45 1
    public function __serialize(): array
46
    {
47 1
        return ['id' => $this->identifier, 'input' => $this->input];
48
    }
49
50 1
    public function __unserialize(array $data): void
51
    {
52 1
        $this->identifier = $data['id'];
53 1
        $this->input = $data['input'];
54 1
    }
55
}
56