BackendsConfig::jsonSerialize()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 11
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
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 BackendsConfig implements JsonSerializable
11
{
12
    /** @var array<string, BackendConfigInterface> */
13
    private array $configs = [];
14
15 2
    public function add(string $username, BackendConfigInterface $backendConfig): self
16
    {
17 2
        $this->configs[$username] = $backendConfig;
18 2
        return $this;
19
    }
20
21
    /**
22
     * @psalm-suppress MixedReturnTypeCoercion
23
     *
24
     * @return array<string,array>
25
     */
26 2
    public function jsonSerialize(): array
27
    {
28
        /**  @var array<string,array> $result */
29 2
        $result = [];
30
31 2
        foreach ($this->configs as $username => $config) {
32
            /** @psalm-suppress MixedAssignment */
33 2
            $result[$username] = $config->jsonSerialize();
34
        }
35
36 2
        return $result;
37
    }
38
}
39