CommandBusFactory   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 14
c 1
b 0
f 0
dl 0
loc 21
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 League\Tactician\CommandBus;
8
use League\Tactician\Handler\CommandHandlerMiddleware;
9
use Psr\Container\ContainerInterface;
10
11
class CommandBusFactory
12
{
13
    public function __invoke(ContainerInterface $container): CommandBus
14
    {
15
        $config = $container->get('config')['command_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 CommandBus(array_merge(
28
            array_map(function (string $middleware) use ($container) {
29
                return $container->get($middleware);
30
            }, $config['middleware']),
31
            [$commandHandlerMiddleware]
32
        ));
33
    }
34
}
35