Passed
Pull Request — master (#17)
by BENOIT
08:21
created

Subscription   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
dl 0
loc 49
rs 10
c 1
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getId() 0 3 1
A getSubscriber() 0 3 1
A setActive() 0 3 1
A jsonSerialize() 0 16 2
1
<?php
2
3
namespace BenTools\MercurePHP\Model;
4
5
final class Subscription implements \JsonSerializable
6
{
7
8
    private string $id;
9
    private string $subscriber;
10
    private string $topic;
11
    private bool $active;
12
    private $payload;
13
14
    public function __construct(string $id, string $subscriber, string $topic, bool $active, $payload)
15
    {
16
        $this->id = $id;
17
        $this->subscriber = $subscriber;
18
        $this->topic = $topic;
19
        $this->active = $active;
20
        $this->payload = $payload;
21
    }
22
23
    public function getId(): string
24
    {
25
        return $this->id;
26
    }
27
28
    public function getSubscriber(): string
29
    {
30
        return $this->subscriber;
31
    }
32
33
    public function setActive(bool $active): void
34
    {
35
        $this->active = $active;
36
    }
37
38
    public function jsonSerialize()
39
    {
40
        $subscription = [
41
            '@context' => 'https://mercure.rocks/',
42
            'id' => $this->id,
43
            'type' => 'Subscription',
44
            'subscriber' => $this->subscriber,
45
            'topic' => $this->topic,
46
            'active' => $this->active,
47
        ];
48
49
        if (null !== $this->payload) {
50
            $subscription['payload'] = $this->payload;
51
        }
52
53
        return $subscription;
54
    }
55
}
56