Passed
Pull Request — master (#17)
by BENOIT
02:04
created

Subscription::jsonSerialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
nc 2
nop 0
dl 0
loc 16
rs 9.9332
c 1
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 = true;
12
    private $payload;
13
14
    public function __construct(string $id, string $subscriber, string $topic, $payload = null)
15
    {
16
        $this->id = $id;
17
        $this->subscriber = $subscriber;
18
        $this->topic = $topic;
19
        $this->payload = $payload;
20
    }
21
22
    public function getId(): string
23
    {
24
        return $this->id;
25
    }
26
27
    public function getSubscriber(): string
28
    {
29
        return $this->subscriber;
30
    }
31
32
    public function isActive(): bool
33
    {
34
        return $this->active;
35
    }
36
37
    public function setActive(bool $active): void
38
    {
39
        $this->active = $active;
40
    }
41
42
    public function getTopic(): string
43
    {
44
        return $this->topic;
45
    }
46
47
    public function getPayload()
48
    {
49
        return $this->payload;
50
    }
51
52
    public function jsonSerialize()
53
    {
54
        $subscription = [
55
            '@context' => 'https://mercure.rocks/',
56
            'id' => $this->id,
57
            'type' => 'Subscription',
58
            'subscriber' => $this->subscriber,
59
            'topic' => $this->topic,
60
            'active' => $this->active,
61
        ];
62
63
        if (null !== $this->payload) {
64
            $subscription['payload'] = $this->payload;
65
        }
66
67
        return $subscription;
68
    }
69
}
70