Factory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 2
A has() 0 4 1
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