Passed
Push — master ( 1f909f...68b106 )
by Thomas
07:19
created

RegistrationOptions::createForUser()   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 1
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\Server\Registration;
4
5
use MadWizard\WebAuthn\Dom\AttestationConveyancePreference;
6
use MadWizard\WebAuthn\Dom\AuthenticatorSelectionCriteria;
7
use MadWizard\WebAuthn\Exception\ConfigurationException;
8
use MadWizard\WebAuthn\Extension\ExtensionInputInterface;
9
use MadWizard\WebAuthn\Server\UserIdentityInterface;
10
11
final class RegistrationOptions
12
{
13
    /**
14
     * @var string|null
15
     */
16
    private $attestation;
17
18
    /**
19
     * @var UserIdentityInterface
20
     */
21
    private $user;
22
23
    /**
24
     * @var AuthenticatorSelectionCriteria|null
25
     */
26
    private $authenticatorSelection;
27
28
    /**
29
     * @var ExtensionInputInterface[]|null
30
     */
31
    private $extensions;
32
33
    /**
34
     * @var bool
35
     */
36
    private $excludeExistingCredentials = false;
37
38 1
    private function __construct(UserIdentityInterface $userIdentity)
39
    {
40 1
        $this->user = $userIdentity;
41 1
    }
42
43 1
    public static function createForUser(UserIdentityInterface $userIdentity): self
44
    {
45 1
        return new RegistrationOptions($userIdentity);
46
    }
47
48 1
    public function getUser(): UserIdentityInterface
49
    {
50 1
        return $this->user;
51
    }
52
53 1
    public function getAttestation(): ?string
54
    {
55 1
        return $this->attestation;
56
    }
57
58
    public function setAttestation(?string $attestation): void
59
    {
60
        if ($attestation !== null && !AttestationConveyancePreference::isValidValue($attestation)) {
61
            throw new ConfigurationException(sprintf('Value "%s" is not a valid attestation conveyance preference.', $attestation));
62
        }
63
        $this->attestation = $attestation;
64
    }
65
66
    public function setAuthenticatorSelection(?AuthenticatorSelectionCriteria $criteria)
67
    {
68
        $this->authenticatorSelection = $criteria;
69
    }
70
71 1
    public function getAuthenticatorSelection(): ?AuthenticatorSelectionCriteria
72
    {
73 1
        return $this->authenticatorSelection;
74
    }
75
76
    public function addExtensionInput(ExtensionInputInterface $input)
77
    {
78
        if ($this->extensions === null) {
79
            $this->extensions = [];
80
        }
81
        $this->extensions[] = $input;
82
    }
83
84 1
    public function getExcludeExistingCredentials(): bool
85
    {
86 1
        return $this->excludeExistingCredentials;
87
    }
88
89
    public function setExcludeExistingCredentials(bool $excludeExistingCredentials): void
90
    {
91
        $this->excludeExistingCredentials = $excludeExistingCredentials;
92
    }
93
94
    /**
95
     * @return ExtensionInputInterface[]|null
96
     */
97 1
    public function getExtensionInputs(): ?array
98
    {
99 1
        return $this->extensions;
100
    }
101
}
102