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

PublisherFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Common\Mercure;
6
7
use Psr\Container\ContainerInterface;
8
use Shlinkio\Shlink\Common\Exception\MercureException;
9
use Symfony\Component\Mercure\Publisher;
10
11
use function sprintf;
12
13
class PublisherFactory
14
{
15 7
    public function __invoke(ContainerInterface $container): Publisher
16
    {
17 7
        $mercureConfig = $container->get('config')['mercure'] ?? [];
18 7
        $mercureHub = $mercureConfig['internal_hub_url'] ?? $mercureConfig['public_hub_url'] ?? null;
19 7
        if ($mercureHub === null) {
20 5
            throw MercureException::missingHubUrl();
21
        }
22
23 2
        $jwtProvider = $container->get(LcobucciJwtProvider::class);
24
25 2
        return new Publisher(sprintf('%s/.well-known/mercure', $mercureHub), $jwtProvider);
26
    }
27
}
28