TokenBinding   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 3 1
A getStatus() 0 3 1
A __construct() 0 5 2
A createFormArray() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace U2FAuthentication\Fido2;
15
16
use Assert\Assertion;
17
use Base64Url\Base64Url;
18
19
class TokenBinding
20
{
21
    public const TOKEN_BINDING_STATUS_PRESENT = 'present';
22
    public const TOKEN_BINDING_STATUS_SUPPORTED = 'supported';
23
    public const TOKEN_BINDING_STATUS_NOT_SUPPORTED = 'not-supported';
24
25
    private $status;
26
27
    private $id;
28
29
    public function __construct(string $status, ?string $id)
30
    {
31
        Assertion::false(self::TOKEN_BINDING_STATUS_PRESENT === $status && !$id, 'The member "id" is required when status is "present"');
32
        $this->status = $status;
33
        $this->id = $id;
34
    }
35
36
    public static function createFormArray(array $json): self
37
    {
38
        Assertion::keyExists($json, 'status', 'The member "status" is required');
39
        $status = $json['status'];
40
        $id = array_key_exists('id', $json) ? Base64Url::decode($json['id']) : null;
41
42
        return new self($status, $id);
43
    }
44
45
    public function getStatus(): string
46
    {
47
        return $this->status;
48
    }
49
50
    public function getId(): ?string
51
    {
52
        return $this->id;
53
    }
54
}
55