PublicKeyCredentialParameters   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 55.56%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 34
ccs 5
cts 9
cp 0.5556
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAsArray() 0 5 1
A __construct() 0 8 2
1
<?php
2
3
namespace MadWizard\WebAuthn\Dom;
4
5
use MadWizard\WebAuthn\Exception\WebAuthnException;
6
7
final class PublicKeyCredentialParameters extends AbstractDictionary
8
{
9
    /**
10
     * Algorithm from COSE.
11
     *
12
     * @var int
13
     */
14
    private $alg;
15
16
    /**
17
     * @var string
18
     */
19
    private $type;
20
21
    /**
22
     * PublicKeyCredentialParameters constructor.
23
     *
24
     * @param int $alg COSEAlgorithmIdentifier;
25
     */
26 1
    public function __construct(int $alg, string $type = PublicKeyCredentialType::PUBLIC_KEY)
27
    {
28 1
        if (!PublicKeyCredentialType::isValidType($type)) {
29
            throw new WebAuthnException(sprintf('Value %s is not a valid PublicKeyCredentialType.', $type));
30
        }
31
32 1
        $this->alg = $alg;
33 1
        $this->type = $type;
34 1
    }
35
36
    public function getAsArray(): array
37
    {
38
        return [
39
            'type' => $this->type,
40
            'alg' => $this->alg,
41
        ];
42
    }
43
}
44