ReallySimpleJWTCreateToken   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 13
dl 0
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 9 1
A __construct() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Auth\Infrastructure\Service;
6
7
use Auth\Container\TokenConfig;
8
use Auth\Model\Identifier;
9
use Auth\Model\Token;
10
use Auth\Service\CreateToken;
11
use DateTime;
12
use ReallySimpleJWT\Token as Jwt;
13
14
class ReallySimpleJWTCreateToken implements CreateToken
15
{
16
    private $secret;
17
    private $expiration;
18
    private $issuer;
19
20
    public function __construct(TokenConfig $config)
21
    {
22
        $this->secret = $config->secret();
23
        $this->expiration = $config->expiration();
24
        $this->issuer = $config->issuer();
25
    }
26
27
    public function __invoke(Identifier $identifier): Token
28
    {
29
        $expiryDate = new DateTime(\sprintf('+%d second', $this->expiration));
30
31
        return Token::fromString(Jwt::getToken(
32
            (string)$identifier,
33
            $this->secret,
34
            $expiryDate->format('Y-m-d H:i:s'),
35
            $this->issuer
36
        ));
37
    }
38
}
39