BackendsConfig::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
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