Passed
Push — main ( 3b8d3e...36fa87 )
by Chema
01:12 queued 13s
created

LightningConfig::setMinSendable()   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 $domain = null;
13
    private ?string $receiver = null;
14
    private ?int $minSendable = null;
15
    private ?int $maxSendable = null;
16
    private BackendsConfig $backends;
17
18
    public function __construct()
19
    {
20
        $this->backends = new BackendsConfig();
21
    }
22
23
    public function setDomain(string $domain): self
24
    {
25
        $this->domain = $domain;
26
        return $this;
27
    }
28
29
    public function setReceiver(string $receiver): self
30
    {
31
        $this->receiver = $receiver;
32
        return $this;
33
    }
34
35
    public function setMinSendable(int $minSendable): self
36
    {
37
        $this->minSendable = $minSendable;
38
        return $this;
39
    }
40
41
    public function setMaxSendable(int $maxSendable): self
42
    {
43
        $this->maxSendable = $maxSendable;
44
        return $this;
45
    }
46
47
    public function addBackend(BackendConfigInterface $backendConfig): self
48
    {
49
        $this->backends->add($backendConfig);
50
        return $this;
51
    }
52
53
    public function jsonSerialize(): array
54
    {
55
        $result = [
56
            'backends' => $this->backends->jsonSerialize(),
57
        ];
58
59
        if ($this->domain !== null) {
60
            $result['domain'] = $this->domain;
61
        }
62
        if ($this->receiver !== null) {
63
            $result['receiver'] = $this->receiver;
64
        }
65
        if ($this->minSendable !== null) {
66
            $result['min-sendable'] = $this->minSendable;
67
        }
68
        if ($this->maxSendable !== null) {
69
            $result['max-sendable'] = $this->maxSendable;
70
        }
71
72
        return $result;
73
    }
74
}
75