ApiTokenLoginHandlerFactory::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 3
nop 1
dl 0
loc 16
ccs 0
cts 14
cp 0
crap 12
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Handler;
6
7
use App\Exception\ConfigException;
8
use App\Infra\Log\AccessLogger;
9
use App\Security\ContredanseProductAccess;
10
use App\Service\Token\TokenManager;
11
use Psr\Container\ContainerInterface;
12
13
class ApiTokenLoginHandlerFactory
14
{
15
    public function __invoke(ContainerInterface $container): ApiTokenLoginHandler
16
    {
17
        $userProvider  = $container->get(\App\Security\UserProviderInterface::class);
18
        $tokenService  = $container->get(TokenManager::class);
19
        $productAccess = $container->get(ContredanseProductAccess::class);
20
        $accessLogger  = $container->get(AccessLogger::class);
21
22
        $config = $container->get('config')['contredanse'] ?? null;
23
        if ($config === null) {
24
            throw new ConfigException("['contredanse'] config key is missing.");
25
        }
26
        if (!is_array($config['auth'] ?? false)) {
27
            throw new ConfigException("['contredanse']['auth'] config key is missing.");
28
        }
29
30
        return new ApiTokenLoginHandler($userProvider, $tokenService, $productAccess, $config['auth'], $accessLogger);
31
    }
32
}
33