StepIteratorCompilerrPass::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
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