Passed
Push — main ( 70cc64...daf31f )
by Chema
01:00 queued 13s
created

LightningConfig   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 33
c 1
b 0
f 0
dl 0
loc 72
ccs 35
cts 35
cp 1
rs 10
wmc 12

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setDomain() 0 5 1
A setMaxSendable() 0 4 1
A setReceiver() 0 4 1
A setMode() 0 4 1
A setMinSendable() 0 4 1
A jsonSerialize() 0 21 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 $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 8
    public function __construct()
20
    {
21 8
        $this->backends = new BackendsConfig();
22
    }
23
24 1
    public function setMode(string $mode): self
25
    {
26 1
        $this->mode = $mode;
27 1
        return $this;
28
    }
29
30 2
    public function setDomain(string $domain): self
31
    {
32 2
        $parseUrl = parse_url($domain);
33 2
        $this->domain = $parseUrl['host'] ?? $domain;
34 2
        return $this;
35
    }
36
37 1
    public function setReceiver(string $receiver): self
38
    {
39 1
        $this->receiver = $receiver;
40 1
        return $this;
41
    }
42
43 1
    public function setMinSendable(int $minSendable): self
44
    {
45 1
        $this->minSendable = $minSendable;
46 1
        return $this;
47
    }
48
49 1
    public function setMaxSendable(int $maxSendable): self
50
    {
51 1
        $this->maxSendable = $maxSendable;
52 1
        return $this;
53
    }
54
55 1
    public function addBackend(BackendConfigInterface $backendConfig): self
56
    {
57 1
        $this->backends->add($backendConfig);
58 1
        return $this;
59
    }
60
61 8
    public function jsonSerialize(): array
62
    {
63 8
        $result = [
64 8
            'mode' => $this->mode,
65 8
            'backends' => $this->backends->jsonSerialize(),
66 8
        ];
67
68 8
        if ($this->domain !== null) {
69 2
            $result['domain'] = $this->domain;
70
        }
71 8
        if ($this->receiver !== null) {
72 1
            $result['receiver'] = $this->receiver;
73
        }
74 8
        if ($this->minSendable !== null) {
75 1
            $result['min-sendable'] = $this->minSendable;
76
        }
77 8
        if ($this->maxSendable !== null) {
78 1
            $result['max-sendable'] = $this->maxSendable;
79
        }
80
81 8
        return $result;
82
    }
83
}
84