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

MergeDefinitions   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 21
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 13 3
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