AuthTokenMiddlewareFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 20
ccs 0
cts 13
cp 0
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 15 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Middleware;
6
7
use App\Exception\ConfigException;
8
use App\Service\Token\TokenManager;
9
use Psr\Container\ContainerInterface;
10
11
class AuthTokenMiddlewareFactory
12
{
13
    /**
14
     * @throws ConfigException
15
     */
16
    public function __invoke(ContainerInterface $container): AuthTokenMiddleware
17
    {
18
        $config = $container->get('config')['token_manager'] ?? null;
19
        if ($config === null) {
20
            throw new ConfigException("['token_manager'] config key is missing.");
21
        }
22
23
        $options = [
24
            AuthTokenMiddleware::OPTION_ALLOW_INSECURE_HTTP => $config['allow_insecure_http'],
25
            AuthTokenMiddleware::OPTION_RELAXED_HOSTS       => $config['relaxed_hosts']
26
        ];
27
28
        return new AuthTokenMiddleware(
29
            $container->get(TokenManager::class),
30
            $options
31
        );
32
    }
33
}
34