QueryBusFactory::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
eloc 13
c 2
b 0
f 2
dl 0
loc 19
rs 9.8333
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace InFw\TacticianAdapter\Factory;
6
7
use InFw\TacticianAdapter\QueryBus;
8
use League\Tactician\Handler\CommandHandlerMiddleware;
9
use Psr\Container\ContainerInterface;
10
11
class QueryBusFactory
12
{
13
    public function __invoke(ContainerInterface $container): QueryBus
14
    {
15
        $config = $container->get('config')['query_bus'];
16
17
        $inflector = $container->get($config['inflector']);
18
        $locator = $container->get($config['locator']);
19
        $nameExtractor = $container->get($config['extractor']);
20
21
        $commandHandlerMiddleware = new CommandHandlerMiddleware(
22
            $nameExtractor,
23
            $locator,
24
            $inflector
25
        );
26
27
        return new QueryBus(array_merge(
28
            array_map(function (string $middleware) use ($container) {
29
                return $container->get($middleware);
30
            }, $config['middleware']),
31
            [$commandHandlerMiddleware]
32
        ));
33
    }
34
}
35