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

AuthenticatorData::getReservedForFutureUse2()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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
use CBOR\CBORObject;
17
18
class AuthenticatorData
19
{
20
    /**
21
     * @var string
22
     */
23
    private $rpIdHash;
24
25
    /**
26
     * @var string
27
     */
28
    private $flags;
29
30
    /**
31
     * @var int
32
     */
33
    private $signCount;
34
35
    /**
36
     * @var null
37
     */
38
    private $attestedCredentialData;
39
40
    /**
41
     * @var null
42
     */
43
    private $extensions;
44
45
    private const FLAG_UP   = 0b00000001;
46
    private const FLAG_RFU1 = 0b00000010;
47
    private const FLAG_UV   = 0b00000100;
48
    private const FLAG_RFU2 = 0b00111000;
49
    private const FLAG_AT   = 0b01000000;
50
    private const FLAG_ED   = 0b10000000;
51
52
    /**
53
     * AuthenticatorData constructor.
54
     *
55
     * @param string $rpIdHash
56
     * @param string $flags
57
     * @param int $signCount
58
     * @param $attestedCredentialData
59
     * @param CBORObject|null $extensions
60
     */
61
    public function __construct(string $rpIdHash, string $flags, int $signCount, $attestedCredentialData, ?CBORObject $extensions)
62
    {
63
        $this->rpIdHash = $rpIdHash;
64
        $this->flags = $flags;
65
        $this->signCount = $signCount;
66
        $this->attestedCredentialData = $attestedCredentialData;
67
        $this->extensions = $extensions;
0 ignored issues
show
Documentation Bug introduced by
It seems like $extensions can also be of type CBOR\CBORObject. However, the property $extensions is declared as type null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getRpIdHash(): string
74
    {
75
        return $this->rpIdHash;
76
    }
77
78
    /**
79
     * @return bool
80
     */
81
    public function isUserPresent(): bool
82
    {
83
        return ord($this->flags) & self::FLAG_UP ? true : false;
84
    }
85
86
    /**
87
     * @return bool
88
     */
89
    public function isUserVerified(): bool
90
    {
91
        return ord($this->flags) & self::FLAG_UV ? true : false;
92
    }
93
94
    /**
95
     * @return bool
96
     */
97
    public function hasAttestedCredentialData(): bool
98
    {
99
        return ord($this->flags) & self::FLAG_AT ? true : false;
100
    }
101
102
    /**
103
     * @return bool
104
     */
105
    public function hasExtensions(): bool
106
    {
107
        return ord($this->flags) & self::FLAG_ED ? true : false;
108
    }
109
110
    /**
111
     * @return int
112
     */
113
    public function getReservedForFutureUse1(): int
114
    {
115
        return ord($this->flags) & self::FLAG_RFU1;
116
    }
117
118
    /**
119
     * @return int
120
     */
121
    public function getReservedForFutureUse2(): int
122
    {
123
        return ord($this->flags) & self::FLAG_RFU2;
124
    }
125
126
    /**
127
     * @return int
128
     */
129
    public function getSignCount(): int
130
    {
131
        return $this->signCount;
132
    }
133
134
    /**
135
     * @return null
136
     */
137
    public function getAttestedCredentialData()
138
    {
139
        return $this->attestedCredentialData;
140
    }
141
142
    /**
143
     * @return null
144
     */
145
    public function getExtensions()
146
    {
147
        return $this->extensions;
148
    }
149
}
150