Passed
Pull Request — master (#3)
by Julien
03:49
created

ProviderPublisher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
            );
32
33
            $publisher = $this->publisher;
34
            $publisher($update);
35
        }
36
    }
37
}
38