ContredanseProductAccessFactory::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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