Completed
Push — master ( d8c018...19ac78 )
by Florent
06:38
created

SubjectChecker   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 2
c 2
b 1
f 1
lcom 0
cbo 2
dl 0
loc 24
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkClaim() 0 11 2
isSubjectAllowed() 0 1 ?
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace Jose\Checker;
13
14
use Assert\Assertion;
15
use Jose\Object\JWTInterface;
16
17
abstract class SubjectChecker implements ClaimCheckerInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function checkClaim(JWTInterface $jwt)
23
    {
24
        if (!$jwt->hasClaim('sub')) {
25
            return [];
26
        }
27
28
        $subject = $jwt->getClaim('sub');
29
        Assertion::true($this->isSubjectAllowed($subject), sprintf('The subject "%s" is not allowed.', $subject));
30
31
        return ['sub'];
32
    }
33
34
    /**
35
     * @param string $subject
36
     *
37
     * @return bool
38
     */
39
    abstract protected function isSubjectAllowed($subject);
40
}
41