Completed
Pull Request — master (#48)
by Alejandro
03:09
created

JwtConfigFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Common\Mercure;
6
7
use Lcobucci\JWT\Configuration;
8
use Lcobucci\JWT\Signer\Hmac\Sha256;
9
use Lcobucci\JWT\Signer\Key;
10
use Psr\Container\ContainerInterface;
11
use Shlinkio\Shlink\Common\Exception\MercureException;
12
13
class JwtConfigFactory
14
{
15 4
    public function __invoke(ContainerInterface $container): Configuration
16
    {
17 4
        $jwtSecret = $container->get('config')['mercure']['jwt_secret'] ?? null;
18 4
        if ($jwtSecret === null) {
19 3
            throw MercureException::missingJwtSecret();
20
        }
21
22 1
        return Configuration::forSymmetricSigner(new Sha256(), new Key((string) $jwtSecret));
23
    }
24
}
25