Completed
Push — master ( d7d555...8d86ce )
by Thomas
06:51 queued 03:43
created

TrustVote::trusted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace MadWizard\WebAuthn\Policy\Trust;
4
5
class TrustVote
6
{
7
    public const VOTE_ABSTAIN = 'abstain';
8
9
    public const VOTE_TRUSTED = 'trusted';
10
11
    public const VOTE_UNTRUSTED = 'untrusted';
12
13
    /**
14
     * @var string
15
     */
16
    private $type;
17
18
    /**
19
     * @var string|null
20
     */
21
    private $reason;
22
23 1
    private function __construct(string $type, ?string $reason = null)
24
    {
25 1
        $this->type = $type;
26 1
        $this->reason = $reason;
27 1
    }
28
29
    public function isAbstain(): bool
30
    {
31
        return $this->type === self::VOTE_ABSTAIN;
32
    }
33
34 1
    public function isTrusted(): bool
35
    {
36 1
        return $this->type === self::VOTE_TRUSTED;
37
    }
38
39
    public function isUntrusted(): bool
40
    {
41
        return $this->type === self::VOTE_UNTRUSTED;
42
    }
43
44
    public function getReason(): ?string
45
    {
46
        return $this->reason;
47
    }
48
49 1
    public static function trusted(): self
50
    {
51 1
        return new TrustVote(self::VOTE_TRUSTED);
52
    }
53
54
    public static function abstain(): self
55
    {
56
        return new TrustVote(self::VOTE_ABSTAIN);
57
    }
58
59
    public static function untrusted(?string $reason = null): self
60
    {
61
        return new TrustVote(self::VOTE_UNTRUSTED, $reason);
62
    }
63
}
64