Completed
Pull Request — master (#67)
by Ross
04:58
created

BusBuildersFromConfig::convert()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace League\Tactician\Bundle\DependencyInjection\Compiler\BusBuilder;
5
6
final class BusBuildersFromConfig
7
{
8
    const DEFAULT_METHOD_INFLECTOR = 'tactician.handler.method_name_inflector.handle';
9
10
    const DEFAULT_BUS_ID = 'default';
11
12 84
    public static function convert(array $config): BusBuilders
13
    {
14 84
        $defaultInflector = $config['method_inflector'] ?? self::DEFAULT_METHOD_INFLECTOR;
15
16 84
        $builders = [];
17 84
        foreach ($config['commandbus'] ?? [] as $busId => $busConfig) {
18 84
            $builders[] = new BusBuilder(
19 84
                $busId,
20 84
                $busConfig['method_inflector'] ?? $defaultInflector,
21 84
                $busConfig['middleware']
22
            );
23
        }
24
25 84
        return new BusBuilders($builders, $config['default_bus'] ?? self::DEFAULT_BUS_ID);
26
    }
27
}
28