SubscriptionStrategyCompilerPass::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 3
eloc 8
c 2
b 0
f 1
nc 3
nop 1
dl 0
loc 15
ccs 0
cts 11
cp 0
crap 12
rs 10
1
<?php
2
3
namespace Terox\SubscriptionBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
class SubscriptionStrategyCompilerPass implements CompilerPassInterface
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public function process(ContainerBuilder $container)
15
    {
16
        $factory            = $container->findDefinition('terox.subscription.registry');
17
        $strategyServiceIds = array_keys($container->findTaggedServiceIds('subscription.strategy'));
18
19
        // Add subscription strategies to factory instance
20
        foreach ($strategyServiceIds as $strategyServiceId) {
21
            $strategy = $container->findDefinition($strategyServiceId);
22
            $tag      = $strategy->getTag('subscription.strategy');
23
24
            if ('subscription' !== $tag[0]['type']) {
25
                continue;
26
            }
27
28
            $factory->addMethodCall('addStrategy', [new Reference($strategyServiceId), $tag[0]['strategy']]);
29
        }
30
    }
31
}
32