PublicKeyCredentialParameters::getAsArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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