Passed
Push — 1.0.x ( e5e1d1...c19ecc )
by Koldo
11:20
created

ToggleConfig::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2.0811

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 2
eloc 10
c 2
b 0
f 1
nc 2
nop 1
dl 0
loc 13
ccs 8
cts 11
cp 0.7272
crap 2.0811
rs 9.9332
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Pheature\Crud\Psr11\Toggle;
6
7
use Webmozart\Assert\Assert;
8
9
final class ToggleConfig
10
{
11
    private string $driver;
12
    private string $apiPrefix;
13
    /** @var array<string, mixed> */
14
    private array $toggles = [];
15
16
    /**
17
     * @param array<string, mixed> $config
18
     */
19 10
    public function __construct(array $config)
20
    {
21 10
        Assert::keyExists($config, 'api_prefix');
22 10
        Assert::keyExists($config, 'driver');
23 10
        Assert::string($config['api_prefix']);
24 10
        Assert::string($config['driver']);
25 10
        $this->apiPrefix = $config['api_prefix'];
26 10
        $this->driver = $config['driver'];
27 10
        if (array_key_exists('toggles', $config)) {
28
            Assert::isArray($config['toggles']);
29
            /** @var array<string, mixed> $toggles */
30
            $toggles = $config['toggles'];
31
            $this->toggles = $toggles;
32
        }
33 10
    }
34
35
    public function apiPrefix(): string
36
    {
37
        return $this->apiPrefix;
38
    }
39
40 10
    public function driver(): string
41
    {
42 10
        return $this->driver;
43
    }
44
45
    /**
46
     * @return array<string, mixed>
47
     */
48 2
    public function toggles(): array
49
    {
50 2
        return $this->toggles;
51
    }
52
}
53