Test Failed
Push — master ( 9eb68a...5271f3 )
by Thomas
02:48
created

AbstractExtensionInput::__serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
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 3
     */
21
    protected $input;
22 3
23
    public function __construct(string $identifier)
24 3
    {
25 1
        $this->identifier = $identifier;
26
27 2
        if (!ExtensionHelper::validExtensionIdentifier($identifier)) {
28
            throw new WebAuthnException(sprintf("Invalid extension identifier '%s'.", $identifier));
29 1
        }
30
    }
31 1
32
    public function getIdentifier(): string
33
    {
34
        return $this->identifier;
35
    }
36
37 2
    /**
38
     * @return mixed
39 2
     */
40
    public function getInput()
41
    {
42
        return $this->input;
43
    }
44
45
    public function __serialize(): array
46
    {
47
        return ['id' => $this->identifier, 'input' => $this->input];
48
    }
49
50
    public function __unserialize(array $data): void
51
    {
52
        $this->identifier = $data['id'];
53
        $this->input = $data['input'];
54
    }
55
}
56