Passed
Pull Request — master (#17)
by BENOIT
03:55
created

Subscription   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
dl 0
loc 44
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getId() 0 3 1
A jsonSerialize() 0 16 2
A getSubscriber() 0 3 1
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 jsonSerialize()
34
    {
35
        $subscription = [
36
            '@context' => 'https://mercure.rocks/',
37
            'id' => $this->id,
38
            'type' => 'Subscription',
39
            'subscriber' => $this->subscriber,
40
            'topic' => $this->topic,
41
            'active' => $this->active,
42
        ];
43
44
        if (null !== $this->payload) {
45
            $subscription['payload'] = $this->payload;
46
        }
47
48
        return $subscription;
49
    }
50
}
51