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

LightningConfig::setDomain()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
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 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