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

PublisherFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 11 2
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