Passed
Push — main ( 36fa87...8ed71a )
by Chema
01:06 queued 13s
created

LightningConfig::setReceiver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpLightning\Config;
6
7
use JsonSerializable;
8
use PhpLightning\Config\Backend\BackendConfigInterface;
9
10
final class LightningConfig implements JsonSerializable
11
{
12
    private string $mode = 'test';
13
    private ?string $domain = null;
14
    private ?string $receiver = null;
15
    private ?int $minSendable = null;
16
    private ?int $maxSendable = null;
17
    private BackendsConfig $backends;
18
19
    public function __construct()
20
    {
21
        $this->backends = new BackendsConfig();
22
    }
23
24
    public function setMode(string $mode): self
25
    {
26
        $this->mode = $mode;
27
        return $this;
28
    }
29
30
    public function setDomain(string $domain): self
31
    {
32
        $this->domain = $domain;
33
        return $this;
34
    }
35
36
    public function setReceiver(string $receiver): self
37
    {
38
        $this->receiver = $receiver;
39
        return $this;
40
    }
41
42
    public function setMinSendable(int $minSendable): self
43
    {
44
        $this->minSendable = $minSendable;
45
        return $this;
46
    }
47
48
    public function setMaxSendable(int $maxSendable): self
49
    {
50
        $this->maxSendable = $maxSendable;
51
        return $this;
52
    }
53
54
    public function addBackend(BackendConfigInterface $backendConfig): self
55
    {
56
        $this->backends->add($backendConfig);
57
        return $this;
58
    }
59
60
    public function jsonSerialize(): array
61
    {
62
        $result = [
63
            'mode' => $this->mode,
64
            'backends' => $this->backends->jsonSerialize(),
65
        ];
66
67
        if ($this->domain !== null) {
68
            $result['domain'] = $this->domain;
69
        }
70
        if ($this->receiver !== null) {
71
            $result['receiver'] = $this->receiver;
72
        }
73
        if ($this->minSendable !== null) {
74
            $result['min-sendable'] = $this->minSendable;
75
        }
76
        if ($this->maxSendable !== null) {
77
            $result['max-sendable'] = $this->maxSendable;
78
        }
79
80
        return $result;
81
    }
82
}
83