Completed
Push — master ( e22550...e221c0 )
by Matze
03:25
created

MergeDefinitions::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
rs 9.4285
cc 3
eloc 8
nc 3
nop 1
1
<?php
2
3
namespace BrainExe\Core\DependencyInjection\CompilerPass;
4
5
use BrainExe\Core\Annotations\CompilerPass;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
9
/**
10
 * @CompilerPass
11
 */
12
class MergeDefinitions implements CompilerPassInterface
13
{
14
    const TAG = 'merge_definition';
15
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function process(ContainerBuilder $container)
20
    {
21
        $services = $container->findTaggedServiceIds(self::TAG);
22
        foreach ($services as $serviceId => $tags) {
23
            $child  = $container->getDefinition($serviceId);
24
            $parent = $container->getDefinition($tags[0]['parent']);
25
26
            foreach ($child->getMethodCalls() as list($method, $arguments)) {
27
                $parent->addMethodCall($method, $arguments);
28
            }
29
            $container->removeDefinition($serviceId);
30
        }
31
    }
32
}
33