StepIteratorCompilerrPass   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 31
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 9 2
A buildTreeStep() 0 18 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Darkilliant\ProcessBundle\DependencyInjection\CompilerPass;
6
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Darkilliant\ProcessBundle\Step\IterableStepInterface;
10
11
/**
12
 * @internal
13
 */
14
class StepIteratorCompilerrPass implements CompilerPassInterface
15
{
16 1
    public function process(ContainerBuilder $container)
17
    {
18 1
        $config = $container->getParameter('darkilliant_process');
19
20 1
        foreach ($config['process'] as $processName => $process) {
21 1
            $config['process'][$processName]['steps'] = $this->buildTreeStep($container, $process['steps']);
22
        }
23
24 1
        $container->setParameter('darkilliant_process', $config);
25 1
    }
26
27 1
    private function buildTreeStep(ContainerBuilder $container, array $steps)
28
    {
29 1
        foreach ($steps as $stepId => $step) {
30 1
            $isStepIterable = in_array(
31 1
                IterableStepInterface::class,
32 1
                class_implements($container->findDefinition($step['service'])->getClass())
33
            );
34
35 1
            if ($isStepIterable) {
36 1
                $children = array_splice($steps, $stepId + 1);
37
38 1
                $steps[$stepId]['children'] = $this->buildTreeStep($container, $children);
39
40 1
                return $steps;
41
            }
42
        }
43
44 1
        return $steps;
45
    }
46
}
47