ContredanseProductAccessFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 18
ccs 0
cts 12
cp 0
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 13 3
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