Passed
Pull Request — master (#18)
by
unknown
08:11
created

AuthenticationExtensionsClientInputs::addInput()   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 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace MadWizard\WebAuthn\Dom;
4
5
// SPEC 5.7 This is a dictionary containing the client extension input values for zero or more WebAuthn extensions, as defined in §9 WebAuthn Extensions.
6
7
use MadWizard\WebAuthn\Extension\ExtensionInputInterface;
8
9
final class AuthenticationExtensionsClientInputs extends AbstractDictionary
10
{
11
    /**
12
     * @var ExtensionInputInterface[]
13
     */
14
    private $inputs = [];
15
16
    public function __construct()
17
    {
18
    }
19
20
    public function addInput(ExtensionInputInterface $input): void
21
    {
22
        $this->inputs[] = $input;
23
    }
24
25
    public function getAsArray(): array
26
    {
27
        $map = [];
28
        foreach ($this->inputs as $input) {
29
            $map[$input->getIdentifier()] = $input->getInput();
30
        }
31
        return $map;
32
    }
33
34
    /**
35
     * @param ExtensionInputInterface[] $inputs
36
     *
37
     * @return AuthenticationExtensionsClientInputs
38
     */
39
    public static function fromArray(array $inputs): self
40
    {
41
        $obj = new AuthenticationExtensionsClientInputs();
42
        foreach ($inputs as $input) {
43
            $obj->addInput($input);
44
        }
45
        return $obj;
46
    }
47
}
48