Passed
Push — master ( 87c83f...33ed15 )
by Sébastien
02:44
created

ContredanseDbFactory::__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 12
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Service\Db;
6
7
use App\Exception\ConfigException;
8
use Psr\Container\ContainerInterface;
9
10
class ContredanseDbFactory
11
{
12
    public function __invoke(ContainerInterface $container): ContredanseDb
13
    {
14
        $config = $container->get('config')['contredanse'] ?? null;
15
        if ($config === null) {
16
            throw new ConfigException("['contredanse'] config key is missing.");
17
        }
18
        if (!is_array($config['db'] ?? false)) {
19
            throw new ConfigException("['contredanse']['db'] config key is missing.");
20
        }
21
22
        return new ContredanseDb(
23
            $config['db']
24
        );
25
    }
26
}
27