Completed
Push — master ( aafa22...ae7595 )
by Alejandro
24s queued 12s
created

LcobucciJwtProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 8 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Common\Mercure;
6
7
use Cake\Chronos\Chronos;
8
use DateTimeImmutable;
9
use Lcobucci\JWT\Configuration;
10
11
class LcobucciJwtProvider
12
{
13
    private Configuration $jwtConfig;
14
    private array $mercureConfig;
15
16 2
    public function __construct(Configuration $jwtConfig, array $mercureConfig)
17
    {
18 2
        $this->jwtConfig = $jwtConfig;
19 2
        $this->mercureConfig = $mercureConfig;
20
    }
21
22 2
    public function __invoke(?DateTimeImmutable $expiresAt = null): string
23
    {
24 2
        return (string) $this->jwtConfig
25 2
            ->createBuilder()
26 2
            ->issuedBy($this->mercureConfig['jwt_issuer'] ?? 'Shlink')
27 2
            ->issuedAt(Chronos::now())
28 2
            ->expiresAt($expiresAt ?? Chronos::now()->addMinutes(10))
29 2
            ->getToken($this->jwtConfig->getSigner(), $this->jwtConfig->getSigningKey());
30
    }
31
}
32