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

NonceChecker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 25
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A checkClaim() 0 4 2
A __construct() 0 3 1
A supportedClaim() 0 3 1
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