Completed
Pull Request — develop (#726)
by Alejandro
05:51
created

MercureUpdatesGenerator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A newVisitUpdate() 0 6 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Core\Mercure;
6
7
use Shlinkio\Shlink\Core\Entity\Visit;
8
use Shlinkio\Shlink\Core\Transformer\ShortUrlDataTransformer;
9
use Symfony\Component\Mercure\Update;
10
11
use function json_encode;
12
13
use const JSON_THROW_ON_ERROR;
14
15
final class MercureUpdatesGenerator implements MercureUpdatesGeneratorInterface
16
{
17
    private const NEW_VISIT_TOPIC = 'https://shlink.io/new_visit';
18
19
    private ShortUrlDataTransformer $transformer;
20
21 1
    public function __construct(array $domainConfig)
22
    {
23 1
        $this->transformer = new ShortUrlDataTransformer($domainConfig);
24
    }
25
26 1
    public function newVisitUpdate(Visit $visit): Update
27
    {
28 1
        return new Update(self::NEW_VISIT_TOPIC, json_encode([
29 1
            'shortUrl' => $this->transformer->transform($visit->getShortUrl()),
30 1
            'visit' => $visit->jsonSerialize(),
31 1
        ], JSON_THROW_ON_ERROR));
32
    }
33
}
34