Passed
Push — 1.0.x ( f3fc24...1b84bc )
by Koldo
02:33
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 $prefix;
13
    /** @var array<string, mixed> */
14
    private array $toggles = [];
15
16
    /**
17
     * @param array<string, mixed> $config
18
     */
19 5
    public function __construct(array $config)
20
    {
21 5
        Assert::keyExists($config, 'prefix');
22 5
        Assert::keyExists($config, 'driver');
23 5
        Assert::string($config['prefix']);
24 5
        Assert::string($config['driver']);
25 5
        $this->prefix = $config['prefix'];
26 5
        $this->driver = $config['driver'];
27 5
        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 5
    }
34
35
    public function prefix(): string
36
    {
37
        return $this->prefix;
38
    }
39
40 5
    public function driver(): string
41
    {
42 5
        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