FirebaseGenerator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 93.33%
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 43
ccs 14
cts 15
cp 0.9333
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getToken() 0 14 1
1
<?php
2
namespace Equip\Auth\Jwt;
3
4
use DateTime;
5
use Firebase\JWT\JWT;
6
use Psr\Http\Message\RequestInterface;
7
8
/**
9
 * Generator for JWT authentication token strings that uses the
10
 * firebase/php-jwt library.
11
 */
12
class FirebaseGenerator implements GeneratorInterface
13
{
14
    /**
15
     * @var RequestInterface
16
     */
17
    protected $request;
18
19
    /**
20
     * @var Configuration
21
     */
22
    protected $config;
23
24
    /**
25
     * @param RequestInterface $request
26
     * @param Configuration $config
27
     */
28 4
    public function __construct(
29
        RequestInterface $request,
30
        Configuration $config
31
    ) {
32 4
        $this->request = $request;
33 4
        $this->config = $config;
34 4
    }
35
36
    /**
37
     * @param array $claims
38
     * @return string
39
     */
40 4
    public function getToken(array $claims = [])
41
    {
42 4
        $issuer = (string) $this->request->getUri();
43 4
        $issued_at = $this->config->getTimestamp();
44 4
        $expiration = $issued_at + $this->config->getTtl();
45 4
        $key = $this->config->getPublicKey();
46 4
        $algorithm = $this->config->getAlgorithm();
47
        $claims += [
48 4
            'iss' => $issuer,
49 4
            'iat' => $issued_at,
50 4
            'exp' => $expiration,
51
        ];
52 4
        return JWT::encode($claims, $key, $algorithm);
53
    }
54
}
55
56