Passed
Push — master ( 5271f3...ae4caa )
by Thomas
02:30
created

AbstractExtensionInput::__serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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