Passed
Push — master ( 106006...c1ddb5 )
by Thomas Mauro
06:38 queued 11s
created

NonceChecker::checkClaim()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\OpenIdClient\ClaimChecker;
6
7
use Jose\Component\Checker\ClaimChecker;
8
use Jose\Component\Checker\InvalidClaimException;
9
use function sprintf;
10
11
final class NonceChecker implements ClaimChecker
12
{
13
    private const CLAIM_NAME = 'nonce';
14
15
    /** @var string */
16
    private $nonce;
17
18 26
    public function __construct(string $nonce)
19
    {
20 26
        $this->nonce = $nonce;
21 26
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26 2
    public function checkClaim($value): void
27
    {
28 2
        if ($value !== $this->nonce) {
29 1
            throw new InvalidClaimException(sprintf('Nonce mismatch, expected %s, got: %s', $this->nonce, $value), self::CLAIM_NAME, $value);
30
        }
31 1
    }
32
33 24
    public function supportedClaim(): string
34
    {
35 24
        return self::CLAIM_NAME;
36
    }
37
}
38