Completed
Push — master ( 4620c1...d09732 )
by Kevin
06:33
created

HasClaimValidator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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