AuthenticationContext   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 57.89%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 15
c 1
b 1
f 0
dl 0
loc 50
ccs 11
cts 19
cp 0.5789
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserHandle() 0 3 1
A __construct() 0 4 1
A addAllowCredentialId() 0 3 1
A getAllowCredentialIds() 0 3 1
A __serialize() 0 6 1
A __unserialize() 0 5 1
1
<?php
2
3
namespace MadWizard\WebAuthn\Server\Authentication;
4
5
use MadWizard\WebAuthn\Credential\CredentialId;
6
use MadWizard\WebAuthn\Credential\UserHandle;
7
use MadWizard\WebAuthn\Format\ByteBuffer;
8
use MadWizard\WebAuthn\Server\AbstractContext;
9
use MadWizard\WebAuthn\Web\Origin;
10
use Serializable;
11
12
final class AuthenticationContext extends AbstractContext implements Serializable
13
{
14
    /**
15
     * @var CredentialId[]
16
     */
17
    private $allowCredentialIds = [];
18
19
    /**
20
     * @var UserHandle|null
21
     */
22
    private $userHandle;
23
24 12
    public function __construct(ByteBuffer $challenge, Origin $origin, string $rpId, ?UserHandle $userHandle)
25
    {
26 12
        parent::__construct($challenge, $origin, $rpId);
27 12
        $this->userHandle = $userHandle;
28 12
    }
29
30 12
    public function addAllowCredentialId(CredentialId $credentialId): void
31
    {
32 12
        $this->allowCredentialIds[] = $credentialId;
33 12
    }
34
35 4
    public function getUserHandle(): ?UserHandle
36
    {
37 4
        return $this->userHandle;
38
    }
39
40
    /**
41
     * @return CredentialId[]
42
     */
43 11
    public function getAllowCredentialIds(): array
44
    {
45 11
        return $this->allowCredentialIds;
46
    }
47
48
    public function __serialize(): array
49
    {
50
        return [
51
            'parent' => parent::__serialize(),
52
            'userHandle' => $this->userHandle,
53
            'allowCredentialIds' => $this->allowCredentialIds,
54
        ];
55
    }
56
57
    public function __unserialize(array $data): void
58
    {
59
        parent::__unserialize($data['parent']);
60
        $this->userHandle = $data['userHandle'];
61
        $this->allowCredentialIds = $data['allowCredentialIds'];
62
    }
63
}
64