Total Complexity | 7 |
Total Lines | 56 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | final class PublicKeyCredentialUserEntity extends PublicKeyCredentialEntity |
||
10 | { |
||
11 | /** |
||
12 | * @var ByteBuffer Binary user handle of the account (max MAX_USER_HANDLE_BYTES) |
||
13 | */ |
||
14 | private $id; |
||
15 | |||
16 | /** |
||
17 | * @var string The user handle of the user account entity |
||
18 | */ |
||
19 | private $displayName; |
||
20 | |||
21 | /** |
||
22 | * PublicKeyCredentialUserEntity constructor. |
||
23 | * |
||
24 | * @param ByteBuffer $id The user handle of the user account entity (max length MAX_USER_HANDLE_BYTES) |
||
25 | * @param string $displayName A human-friendly name for the user account. Used for display purposes only, may be truncated by authenticators if too long |
||
26 | * |
||
27 | * @throws WebAuthnException |
||
28 | */ |
||
29 | 7 | public function __construct(string $name, ByteBuffer $id, string $displayName) |
|
30 | { |
||
31 | 7 | parent::__construct($name); |
|
32 | 7 | $this->setId($id); |
|
33 | 5 | $this->displayName = $displayName; |
|
34 | 5 | } |
|
35 | |||
36 | 2 | public function getId(): ByteBuffer |
|
37 | { |
||
38 | 2 | return $this->id; |
|
39 | } |
||
40 | |||
41 | 7 | private function setId(ByteBuffer $id): void |
|
42 | { |
||
43 | 7 | if ($id->isEmpty()) { |
|
44 | 1 | throw new WebAuthnException('User handle cannot be empty.'); |
|
45 | } |
||
46 | |||
47 | 6 | if ($id->getLength() > UserHandle::MAX_USER_HANDLE_BYTES) { |
|
48 | 1 | throw new WebAuthnException(sprintf('User handle cannot be larger than %d bytes.', UserHandle::MAX_USER_HANDLE_BYTES)); |
|
49 | } |
||
50 | 5 | $this->id = $id; |
|
51 | 5 | } |
|
52 | |||
53 | 2 | public function getDisplayName(): string |
|
54 | { |
||
55 | 2 | return $this->displayName; |
|
56 | } |
||
57 | |||
58 | 3 | public function getAsArray(): array |
|
65 | ] |
||
66 | ); |
||
67 | } |
||
68 | } |
||
69 |