ExpectedClaimValidator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4286
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Zenstruck\JWT\Validator;
4
5
use Zenstruck\JWT\Exception\Validation\ClaimMismatch;
6
use Zenstruck\JWT\Token;
7
use Zenstruck\JWT\Validator;
8
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 */
12
class ExpectedClaimValidator implements Validator
13
{
14
    private $claim;
15
    private $expected;
16
17
    /**
18
     * @param string $claim
19
     * @param mixed  $expected
20
     */
21 20
    public function __construct($claim, $expected)
22
    {
23 20
        $this->claim = $claim;
24 20
        $this->expected = $expected;
25 20
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 19
    final public function validate(Token $token)
31
    {
32 19
        (new HasClaimValidator($this->claim))->validate($token);
33
34 12
        $actual = $token->get($this->claim);
35
36 12
        if ($this->expected !== $actual) {
37 5
            throw new ClaimMismatch($this->claim, $actual, $this->expected, $token);
38
        }
39 7
    }
40
}
41