Passed
Push — master ( 022bc2...5c7e77 )
by Thomas
03:17
created

RegistrationOptions::setAuthenticatorAttachment()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 3
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 12
rs 10
1
<?php
2
3
namespace MadWizard\WebAuthn\Server\Registration;
4
5
use MadWizard\WebAuthn\Dom\AttestationConveyancePreference;
6
use MadWizard\WebAuthn\Dom\AuthenticatorAttachment;
7
use MadWizard\WebAuthn\Dom\ResidentKeyRequirement;
8
use MadWizard\WebAuthn\Dom\UserVerificationRequirement;
9
use MadWizard\WebAuthn\Exception\ConfigurationException;
10
use MadWizard\WebAuthn\Exception\UnexpectedValueException;
11
use MadWizard\WebAuthn\Extension\RegistrationExtensionInputInterface;
12
use MadWizard\WebAuthn\Server\UserIdentityInterface;
13
14
final class RegistrationOptions     // TODO: add timeout (via trait?)
15
{
16
    /**
17
     * @var string|null
18
     */
19
    private $attestation;
20
21
    /**
22
     * @var UserIdentityInterface
23
     */
24
    private $user;
25
26
    /**
27
     * @var bool
28
     */
29
    private $excludeExistingCredentials = false;
30
31
    /**
32
     * @var RegistrationExtensionInputInterface[]
33
     */
34
    private $extensions = [];
35
36
    /**
37
     * @var int|null
38
     */
39
    private $timeout;
40
41
    /**
42
     * @var string|null
43
     *
44
     * @see ResidentKeyRequirement
45
     */
46
    private $residentKey;
47
48
    /**
49
     * @var string|null
50
     *
51
     * @see AuthenticatorAttachment
52
     */
53
    private $authenticatorAttachment;
54
55
    /**
56
     * @var string|null
57
     *
58
     * @see UserVerificationRequirement
59
     */
60
    private $userVerification;
61
62 1
    private function __construct(UserIdentityInterface $userIdentity)
63
    {
64 1
        $this->user = $userIdentity;
65 1
    }
66
67 1
    public static function createForUser(UserIdentityInterface $userIdentity): self
68
    {
69 1
        return new RegistrationOptions($userIdentity);
70
    }
71
72 1
    public function getUser(): UserIdentityInterface
73
    {
74 1
        return $this->user;
75
    }
76
77 1
    public function getAttestation(): ?string
78
    {
79 1
        return $this->attestation;
80
    }
81
82
    public function setAttestation(?string $attestation): void
83
    {
84
        if ($attestation !== null && !AttestationConveyancePreference::isValidValue($attestation)) {
85
            throw new ConfigurationException(sprintf('Value "%s" is not a valid attestation conveyance preference.', $attestation));
86
        }
87
        $this->attestation = $attestation;
88
    }
89
90 1
    public function getExcludeExistingCredentials(): bool
91
    {
92 1
        return $this->excludeExistingCredentials;
93
    }
94
95
    public function setExcludeExistingCredentials(bool $excludeExistingCredentials): void
96
    {
97
        $this->excludeExistingCredentials = $excludeExistingCredentials;
98
    }
99
100
    public function addExtensionInput(RegistrationExtensionInputInterface $input): void
101
    {
102
        $this->extensions[] = $input;
103
    }
104
105
    /**
106
     * @return RegistrationExtensionInputInterface[]
107
     */
108 1
    public function getExtensionInputs(): array
109
    {
110 1
        return $this->extensions;
111
    }
112
113 1
    public function getTimeout(): ?int
114
    {
115 1
        return $this->timeout;
116
    }
117
118
    public function setTimeout(?int $timeout): void
119
    {
120
        $this->timeout = $timeout;
121
    }
122
123
    /**
124
     * @return string
125
     */
126 1
    public function getResidentKey(): ?string
127
    {
128 1
        return $this->residentKey;
129
    }
130
131
    /**
132
     * @param string $residentKey
133
     */
134
    public function setResidentKey(?string $residentKey): void
135
    {
136
        if ($residentKey !== null && !ResidentKeyRequirement::isValidValue($residentKey)) {
137
            throw new UnexpectedValueException('Invalid ResidentKeyRequirement value.');
138
        }
139
        $this->residentKey = $residentKey;
140
    }
141
142 1
    public function getAuthenticatorAttachment(): ?string
143
    {
144 1
        return $this->authenticatorAttachment;
145
    }
146
147
    public function setAuthenticatorAttachment(?string $authenticatorAttachment): void
148
    {
149
        if ($authenticatorAttachment !== null && !AuthenticatorAttachment::isValidValue($authenticatorAttachment)) {
150
            throw new UnexpectedValueException('Invalid AuthenticatorAttachment value.');
151
        }
152
        $this->authenticatorAttachment = $authenticatorAttachment;
153
    }
154
155 1
    public function getUserVerification(): ?string
156
    {
157 1
        return $this->userVerification;
158
    }
159
160
    public function setUserVerification(?string $userVerification): void
161
    {
162
        if ($userVerification !== null && !UserVerificationRequirement::isValidValue($userVerification)) {
163
            throw new UnexpectedValueException('Invalid UserVerificationRequirement value.');
164
        }
165
        $this->userVerification = $userVerification;
166
    }
167
}
168