RegisterReceiverFactoryPass::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 2
b 0
f 0
nc 2
nop 1
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 2
rs 10
1
<?php
2
3
namespace Bdf\QueueBundle\DependencyInjection\Compiler;
4
5
use Bdf\Queue\Consumer\Receiver\Builder\ReceiverFactory;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Reference;
9
use Symfony\Component\ExpressionLanguage\Expression;
10
11
/**
12
 * Register all the objects provide a factory for receivers.
13
 */
14
final class RegisterReceiverFactoryPass implements CompilerPassInterface
15
{
16
    public const CONFIGURATOR_TAG_NAME = 'bdf_queue.receiver_factory';
17
18
    /**
19
     * {@inheritdoc}
20
     */
21 7
    public function process(ContainerBuilder $container)
22
    {
23 7
        $factory = $container->getDefinition(ReceiverFactory::class);
24
25 7
        foreach ($container->findTaggedServiceIds(self::CONFIGURATOR_TAG_NAME) as $serviceId => $tag) {
26 7
            $factory->addMethodCall('addFactory', [
27 7
                new Expression("service('".addslashes($serviceId)."').getReceiverNames()"),
28 7
                [new Reference($serviceId), 'create'],
29 7
            ]);
30
        }
31
    }
32
}
33