Passed
Push — master ( 08dd0c...2460e1 )
by Koldo
02:21
created

CommandBusFactory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 19 1
1
<?php
2
3
namespace InFw\TacticianAdapter\Factory;
4
5
use League\Tactician\CommandBus;
6
use League\Tactician\Handler\CommandHandlerMiddleware;
7
use Interop\Container\ContainerInterface;
8
9
class CommandBusFactory
10
{
11
    /**
12
     * @param ContainerInterface $container
13
     *
14
     * @return CommandBus
15
     */
16
    public function __invoke(ContainerInterface $container)
17
    {
18
        $config = $container->get('config')['command-bus'];
19
20
        $inflector = $container->get($config['inflector']);
21
        $locator = $container->get($config['locator']);
22
        $nameExtractor = $container->get($config['extractor']);
23
24
        $commandHandlerMiddleware = new CommandHandlerMiddleware(
25
            $nameExtractor,
26
            $locator,
27
            $inflector
28
        );
29
30
        return new CommandBus(array_merge(
31
            array_map(function (string $middleware) use ($container) {
32
                return $container->get($middleware);
33
            }, $config['middleware']),
34
            [$commandHandlerMiddleware]
35
        ));
36
    }
37
}
38