ValidationContext   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 57
ccs 8
cts 16
cp 0.5
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A withReferenceUnixTime() 0 5 1
A getClockLeeway() 0 3 1
A getReferenceUnixTime() 0 3 1
A getAllowedAlgorithms() 0 3 1
A __construct() 0 5 1
A getKey() 0 3 1
1
<?php
2
3
namespace MadWizard\WebAuthn\Pki\Jwt;
4
5
use MadWizard\WebAuthn\Crypto\CoseKeyInterface;
6
7
final class ValidationContext
8
{
9
    public const DEFAULT_CLOCK_LEEWAY = 1 * 60;
10
11
    /**
12
     * @var string[]
13
     */
14
    private $allowedAlgorithms;
15
16
    /**
17
     * @var CoseKeyInterface
18
     */
19
    private $key;
20
21
    /**
22
     * @var int|null
23
     */
24
    private $referenceUnixTime;
25
26
    /**
27
     * @param string[] $allowedAlgorithms
28
     */
29 5
    public function __construct(array $allowedAlgorithms, CoseKeyInterface $key)
30
    {
31 5
        $this->key = $key;
32
        // TODO: check types
33 5
        $this->allowedAlgorithms = $allowedAlgorithms;
34 5
    }
35
36
    /**
37
     * @return string[]
38
     */
39 5
    public function getAllowedAlgorithms(): array
40
    {
41 5
        return $this->allowedAlgorithms;
42
    }
43
44 4
    public function getKey(): CoseKeyInterface
45
    {
46 4
        return $this->key;
47
    }
48
49
    public function getReferenceUnixTime(): int
50
    {
51
        return $this->referenceUnixTime ?? time();
52
    }
53
54
    public function getClockLeeway(): int
55
    {
56
        return self::DEFAULT_CLOCK_LEEWAY;
57
    }
58
59
    public function withReferenceUnixTime(int $timestamp): self
60
    {
61
        $copy = clone $this;
62
        $copy->referenceUnixTime = $timestamp;
63
        return $copy;
64
    }
65
}
66