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

Subscription::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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