Test Failed
Push — master ( 808db7...ed009c )
by Koldo
02:11
created

QueryBusFactory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 1
eloc 14
c 1
b 0
f 1
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 19 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
    /**
14
     * @param ContainerInterface $container
15
     *
16
     * @return CommandBus
17
     */
18
    public function __invoke(ContainerInterface $container): QueryBus
19
    {
20
        $config = $container->get('config')['query_bus'];
21
22
        $inflector = $container->get($config['inflector']);
23
        $locator = $container->get($config['locator']);
24
        $nameExtractor = $container->get($config['extractor']);
25
26
        $commandHandlerMiddleware = new CommandHandlerMiddleware(
27
            $nameExtractor,
28
            $locator,
29
            $inflector
30
        );
31
32
        return new QueryBus(array_merge(
33
            array_map(function (string $middleware) use ($container) {
34
                return $container->get($middleware);
35
            }, $config['middleware']),
36
            [$commandHandlerMiddleware]
37
        ));
38
    }
39
}
40