TacticianMiddlewareCompilerPass::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 7
cp 0.8571
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3.0261
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\TacticianQueueBundle\DependencyInjection\CompilerPass;
6
7
use Lamoda\TacticianQueue\Middleware\QueueProducerStrategy\ChainedStrategy;
8
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\DependencyInjection\Reference;
11
12
final class TacticianMiddlewareCompilerPass implements CompilerPassInterface
13
{
14
    private const QUEUE_PRODUCER_CHAIN_STRATEGY = ChainedStrategy::class;
15
    private const TACTICIAN_MIDDLEWARE_STRATEGY_TAG = 'tactician_queue.job_producing_strategy';
16
17 1
    public function process(ContainerBuilder $container)
18
    {
19 1
        if (!$container->hasDefinition(static::QUEUE_PRODUCER_CHAIN_STRATEGY)) {
20
            return;
21
        }
22
23 1
        $chainDefinition = $container->getDefinition(static::QUEUE_PRODUCER_CHAIN_STRATEGY);
24
25 1
        foreach ($container->findTaggedServiceIds(self::TACTICIAN_MIDDLEWARE_STRATEGY_TAG) as $serviceId => $tags) {
26 1
            $chainDefinition->addMethodCall('addStrategy', [new Reference($serviceId)]);
27
        }
28 1
    }
29
}
30