Passed
Pull Request — main (#5)
by Chema
02:24
created

LightningConfig   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 63
ccs 0
cts 30
cp 0
rs 10
wmc 11

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setDomain() 0 4 1
A setMaxSendable() 0 4 1
A setReceiver() 0 4 1
A setMinSendable() 0 4 1
A jsonSerialize() 0 20 5
A addBackend() 0 4 1
A __construct() 0 3 1
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