Passed
Push — master ( 6cdc56...c1fd3a )
by Thomas
04:06
created

ValidationContext::withReferenceUnixTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
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