RegisterConsumers   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 32
ccs 9
cts 12
cp 0.75
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 5 1
A replaceArgumentWithReference() 0 15 3
1
<?php
2
3
namespace Happyr\Mq2phpBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
/**
10
 * Register the message bus argument to our consumer.
11
 *
12
 * @author Tobias Nyholm <[email protected]>
13
 */
14
class RegisterConsumers implements CompilerPassInterface
15
{
16
    /**
17
     * @param ContainerBuilder $container
18
     */
19 1
    public function process(ContainerBuilder $container)
20
    {
21 1
        $this->replaceArgumentWithReference($container, 'happyr.mq2php.extendable_command_envelope_consumer', 'simple_bus.asynchronous.command_bus');
22 1
        $this->replaceArgumentWithReference($container, 'happyr.mq2php.extendable_event_envelope_consumer', 'simple_bus.asynchronous.event_bus');
23 1
    }
24
25
    /**
26
     * @param ContainerBuilder $container
27
     * @param string           $serviceId
28
     * @param string           $referenceId
29
     */
30 1
    private function replaceArgumentWithReference(ContainerBuilder $container, $serviceId, $referenceId)
31
    {
32 1
        if (!$container->hasDefinition($serviceId)) {
33
            return;
34
        }
35
36
        // If there is not $referenceId the $service has no use
37 1
        if (!$container->hasDefinition($referenceId)) {
38
            $container->removeDefinition($serviceId);
39
40
            return;
41
        }
42
43 1
        $container->getDefinition($serviceId)->replaceArgument(1, new Reference($referenceId));
44 1
    }
45
}
46