ToggleConfigFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 8
c 4
b 0
f 0
dl 0
loc 18
ccs 7
cts 7
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Pheature\Crud\Psr11\Toggle;
6
7
use ArrayObject;
8
use Psr\Container\ContainerInterface;
9
use Webmozart\Assert\Assert;
10
11
/**
12
 * @psalm-import-type ToggleConfigOptions from ToggleConfig
13
 */
14
final class ToggleConfigFactory
15
{
16
    private const MISSING_CONFIG = '"pheature_flags" configuration not found in container';
17
18 4
    public function __invoke(ContainerInterface $container): ToggleConfig
19
    {
20
        /**
21
         * @var array{pheature_flags?: ToggleConfigOptions|null}|ArrayObject<string, ToggleConfigOptions|null> $config
22
         */
23 4
        $config = $container->get('config');
24 4
        if ($config instanceof ArrayObject) {
25 1
            $config = $config->getArrayCopy();
26
        }
27
28 4
        Assert::keyExists($config, 'pheature_flags', self::MISSING_CONFIG);
29 3
        Assert::isArray($config['pheature_flags'], self::MISSING_CONFIG);
30
31 3
        return new ToggleConfig($config['pheature_flags']);
32
    }
33
}
34