Passed
Push — 1.0.x ( 48f1ab...7d1554 )
by Koldo
30:19 queued 27:51
created

ToggleConfigFactory::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Pheature\Crud\Psr11\Toggle;
6
7
use Psr\Container\ContainerInterface;
8
use Webmozart\Assert\Assert;
9
10
final class ToggleConfigFactory
11
{
12
    private const MISSING_CONFIG = '"pheature_flags" configuration not found in container';
13
14 3
    public function __invoke(ContainerInterface $container): ToggleConfig
15
    {
16
        /** @var array<string, mixed>|mixed $config */
17 3
        $config = $container->get('config');
18 3
        Assert::isArray($config);
19 3
        Assert::keyExists($config, 'pheature_flags', self::MISSING_CONFIG);
20 2
        Assert::isArray($config['pheature_flags'], self::MISSING_CONFIG);
21
22
        /** @var array<string, mixed> $pheatureConfig */
23 2
        $pheatureConfig = $config['pheature_flags'];
24
25 2
        return new ToggleConfig($pheatureConfig);
26
    }
27
}
28