Passed
Push — 1.0.x ( 6cc73c...a7af17 )
by Koldo
02:37
created

FeatureRepositoryFactory::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 2
dl 0
loc 14
ccs 7
cts 7
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Pheature\Crud\Psr11\Toggle;
6
7
use Doctrine\DBAL\Connection;
8
use InvalidArgumentException;
9
use Pheature\Core\Toggle\Write\FeatureRepository;
10
use Pheature\Dbal\Toggle\Write\DbalFeatureRepository;
11
use Pheature\InMemory\Toggle\InMemoryFeatureRepository;
12
use Psr\Container\ContainerInterface;
13
14
final class FeatureRepositoryFactory
15
{
16 3
    public function __invoke(ContainerInterface $container): FeatureRepository
17
    {
18
        /** @var ToggleConfig $config */
19 3
        $config = $container->get(ToggleConfig::class);
20
        /** @var ?Connection $connection */
21 3
        $connection = $container->get(Connection::class);
22
23 3
        return self::create($config, $connection);
24
    }
25
26 5
    public static function create(ToggleConfig $config, ?Connection $connection): FeatureRepository
27
    {
28 5
        $driver = $config->driver();
29
30 5
        if ('inmemory' === $driver) {
31 2
            return new InMemoryFeatureRepository();
32
        }
33
34 3
        if ('dbal' === $driver) {
35
            /** @var Connection $connection */
36 2
            return new DbalFeatureRepository($connection);
37
        }
38
39 1
        throw new InvalidArgumentException('Valid driver required');
40
    }
41
}
42