TemplateIdGuesserCompilerPass::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.7666
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Dekalee\MailjetBundle\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
 * Class TemplateIdGuesserCompilerPass
11
 */
12
class TemplateIdGuesserCompilerPass implements CompilerPassInterface
13
{
14
    /**
15
     * You can modify the container here before it is dumped to PHP code.
16
     *
17
     * @param ContainerBuilder $container
18
     */
19
    public function process(ContainerBuilder $container)
20
    {
21
        $managerName = 'dekalee_mailjet.guesser.template_id.manager';
22
        $tagName = 'dekalee_mailjet.guesser.template_id.strategy';
23
        $methodName = 'addGuesser';
24
25
        if (!$container->hasDefinition($managerName)) {
26
            return;
27
        }
28
        $manager = $container->getDefinition($managerName);
29
        $strategies = $container->findTaggedServiceIds($tagName);
30
        foreach ($strategies as $id => $attributes) {
31
            $manager->addMethodCall($methodName, array(new Reference($id)));
32
        }
33
    }
34
}
35