ExpectedClaimValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 1
cbo 3
dl 0
loc 29
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A validate() 0 10 2
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