Factory::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6
Metric Value
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4286
cc 2
eloc 4
nc 2
nop 2
crap 6
1
<?php
2
3
namespace Tymon\JWTAuth\Claims;
4
5
class Factory
6
{
7
    /**
8
     * @var array
9
     */
10
    private static $classMap = [
11
        'aud' => 'Tymon\JWTAuth\Claims\Audience',
12
        'exp' => 'Tymon\JWTAuth\Claims\Expiration',
13
        'iat' => 'Tymon\JWTAuth\Claims\IssuedAt',
14
        'iss' => 'Tymon\JWTAuth\Claims\Issuer',
15
        'jti' => 'Tymon\JWTAuth\Claims\JwtId',
16
        'nbf' => 'Tymon\JWTAuth\Claims\NotBefore',
17
        'sub' => 'Tymon\JWTAuth\Claims\Subject'
18
    ];
19
20
    /**
21
     * Get the instance of the claim when passing the name and value
22
     *
23
     * @param  string  $name
24
     * @param  mixed   $value
25
     * @return \Tymon\JWTAuth\Claims\Claim
26
     */
27
    public function get($name, $value)
28
    {
29
        if ($this->has($name)) {
30
            return new self::$classMap[$name]($value);
31
        }
32
33
        return new Custom($name, $value);
34
    }
35
36
    /**
37
     * Check whether the claim exists
38
     *
39
     * @param  string  $name
40
     * @return boolean
41
     */
42
    public function has($name)
43
    {
44
        return array_key_exists($name, self::$classMap);
45
    }
46
}
47