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

AuthenticationExtensionsClientInputs::getAsArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
ccs 0
cts 5
cp 0
crap 6
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