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

LcobucciJwtProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
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