ProviderPublisher::publishProviderUpdate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 15
rs 9.9666
1
<?php
2
3
namespace App\Mercure;
4
5
6
use App\Document\Provider;
7
use Symfony\Component\Mercure\Publisher;
8
use Symfony\Component\Mercure\Update;
9
10
class ProviderPublisher
11
{
12
    private $publisher;
13
    private $mercureEnabled;
14
15
    public function __construct(Publisher $publisher, bool $mercureEnabled = true)
16
    {
17
        $this->publisher = $publisher;
18
        $this->mercureEnabled = $mercureEnabled;
19
    }
20
21
    public function publishProviderUpdate(Provider $provider)
22
    {
23
24
        if($this->mercureEnabled) {
25
            $update = new Update(
26
                'http://twity.io/p/' . $provider->getName(),
27
                json_encode([
28
                    'provider' => $provider->getName(),
29
                    'updateInProgress' => $provider->getUpdateInProgress()
30
                ]),
31
                ['http://twity.io/user']
32
            );
33
34
            $publisher = $this->publisher;
35
            $publisher($update);
36
        }
37
    }
38
}
39