Failed Conditions
Push — master ( bbfade...32fb37 )
by Florent
02:44
created

TokenBinding::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 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
class TokenBinding
17
{
18
    public const TOKEN_BINDING_STATUS_PRESENT = 'present';
19
    public const TOKEN_BINDING_STATUS_SUPPORTED = 'supported';
20
    public const TOKEN_BINDING_STATUS_NOT_SUPPORTED = 'not-supported';
21
    /**
22
     * @var string
23
     */
24
    private $status;
25
26
    /**
27
     * @var null|string
28
     */
29
    private $id;
30
31
    /**
32
     * TokenBinding constructor.
33
     *
34
     * @param string      $status
35
     * @param null|string $id
36
     */
37
    public function __construct(string $status, ?string $id)
38
    {
39
        $this->status = $status;
40
        $this->id = $id;
41
    }
42
43
    /**
44
     * @param array $json
45
     *
46
     * @return TokenBinding
47
     */
48
    public static function createFormJson(array $json): self
49
    {
50
        if (!array_key_exists('status', $json)) {
51
            throw new \InvalidArgumentException();
52
        }
53
54
        return new self(
55
            $json['status'],
56
            array_key_exists('id', $json) ? $json['status'] : null
57
        );
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getStatus(): string
64
    {
65
        return $this->status;
66
    }
67
68
    /**
69
     * @return null|string
70
     */
71
    public function getId(): ?string
72
    {
73
        return $this->id;
74
    }
75
}
76