SimpleAdapterFactory::__invoke()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 20
rs 9.8333
cc 4
nc 4
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Ctw\Middleware\HtmlMinifierMiddleware\Adapter\SimpleAdapter;
5
6
use Ctw\Middleware\HtmlMinifierMiddleware\HtmlMinifierMiddleware;
7
use Psr\Container\ContainerInterface;
8
9
class SimpleAdapterFactory
10
{
11
    public function __invoke(ContainerInterface $container): SimpleAdapter
12
    {
13
        $config = [];
14
        if ($container->has('config')) {
15
            $globalConfig = $container->get('config');
16
            assert(is_array($globalConfig));
17
            $middlewareConfig = $globalConfig[HtmlMinifierMiddleware::class] ?? [];
18
            assert(is_array($middlewareConfig));
19
            $adapterConfig = $middlewareConfig[SimpleAdapter::class] ?? [];
20
            assert(is_array($adapterConfig));
21
            $config = $adapterConfig;
22
        }
23
24
        $adapter = new SimpleAdapter();
25
26
        if ((is_countable($config) ? count($config) : 0) > 0) {
27
            $adapter->setConfig($config);
28
        }
29
30
        return $adapter;
31
    }
32
}
33