Test Failed
Pull Request — main (#15)
by
unknown
02:14
created

LightningConfig   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setDomain() 0 5 1
A setSendableRange() 0 4 1
A setReceiver() 0 4 1
A jsonSerialize() 0 20 6
A addBackend() 0 5 1
A setCallbackUrl() 0 4 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
use PhpLightning\Shared\Value\SendableRange;
10
11
final class LightningConfig implements JsonSerializable
12
{
13
    private ?string $domain = null;
14
    private ?string $receiver = null;
15
    private ?SendableRange $sendableRange = null;
16
    private ?string $callbackUrl = null;
17
    private ?BackendsConfig $backends = null;
18 4
19
    public function setDomain(string $domain): self
20 4
    {
21 4
        $parseUrl = parse_url($domain);
22 4
        $this->domain = $parseUrl['host'] ?? $domain;
23
        return $this;
24
    }
25 3
26
    public function setReceiver(string $receiver): self
27 3
    {
28 3
        $this->receiver = $receiver;
29
        return $this;
30
    }
31 3
32
    public function setSendableRange(int $min, int $max): self
33 3
    {
34 3
        $this->sendableRange = SendableRange::withMinMax($min, $max);
35
        return $this;
36
    }
37 3
38
    public function setCallbackUrl(string $callbackUrl): self
39 3
    {
40 3
        $this->callbackUrl = $callbackUrl;
41 3
        return $this;
42
    }
43
44 8
    public function addBackend(BackendConfigInterface $backendConfig): self
45
    {
46 8
        $this->backends ??= new BackendsConfig();
47 8
        $this->backends->add($backendConfig);
48 3
        return $this;
49
    }
50 8
51 4
    public function jsonSerialize(): array
52
    {
53 8
        $result = [];
54 3
        if ($this->backends !== null) {
55
            $result['backends'] = $this->backends->jsonSerialize();
56 8
        }
57 3
        if ($this->domain !== null) {
58
            $result['domain'] = $this->domain;
59
        }
60 8
        if ($this->receiver !== null) {
61
            $result['receiver'] = $this->receiver;
62
        }
63
        if ($this->sendableRange !== null) {
64
            $result['sendable-range'] = $this->sendableRange;
65
        }
66
        if ($this->callbackUrl !== null) {
67
            $result['callback-url'] = $this->callbackUrl;
68
        }
69
70
        return $result;
71
    }
72
}
73