FirebaseParser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A parseToken() 0 13 2
1
<?php
2
namespace Equip\Auth\Jwt;
3
4
use Equip\Auth\Exception\InvalidException;
5
use Equip\Auth\Jwt\Configuration;
6
use Equip\Auth\Token;
7
use Firebase\JWT\ExpiredException;
8
use Firebase\JWT\JWT;
9
10
/**
11
 * Parser for JWT authentication token strings that uses the firebase/php-jwt
12
 * library.
13
 */
14
class FirebaseParser implements ParserInterface
15
{
16
    /**
17
     * @var Configuration
18
     */
19
    protected $config;
20
21
    /**
22
     * @param Configuration $config
23
     */
24 3
    public function __construct(Configuration $config)
25
    {
26 3
        $this->config = $config;
27 3
    }
28
29
    /**
30
     * @inheritDoc
31
     */
32 3
    public function parseToken($token)
33
    {
34
        try {
35 3
            $metadata = (array) JWT::decode(
36 3
                (string) $token,
37 3
                $this->config->getPublicKey(),
38 3
                [$this->config->getAlgorithm()]
39 3
            );
40 3
        } catch (ExpiredException $e) {
41 1
            throw InvalidException::tokenExpired($token, $e);
42
        }
43 2
        return new Token($token, $metadata);
44
    }
45
}
46