Passed
Push — 1.0.x ( f3fc24...1b84bc )
by Koldo
02:33
created

ToggleConfig   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 72.21%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 17
c 2
b 0
f 1
dl 0
loc 42
ccs 13
cts 18
cp 0.7221
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A prefix() 0 3 1
A driver() 0 3 1
A toggles() 0 3 1
A __construct() 0 13 2
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