Completed
Pull Request — master (#154)
by De Cramer
02:58
created

VoteFactoriesPass   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 15 3
1
<?php
2
3
4
namespace eXpansion\Bundle\VoteManager\DependencyInjection\Compiler;
5
6
use eXpansion\Bundle\VoteManager\Services\VoteService;
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Reference;
10
11
12
/**
13
 * Class VoteFactoriesPass
14
 *
15
 * @package eXpansion\Bundle\VoteManager\DependencyInjection\Compiler;
16
 * @author  oliver de Cramer <[email protected]>
17
 */
18
class VoteFactoriesPass implements CompilerPassInterface
19
{
20
21
    /**
22
     * You can modify the container here before it is dumped to PHP code.
23
     *
24
     * @param ContainerBuilder $container
25
     */
26
    public function process(ContainerBuilder $container)
27
    {
28
        if (!$container->has(VoteService::class)) {
29
            return;
30
        }
31
        $definition = $container->getDefinition(VoteService::class);
32
33
        $voteFactorieReferences = [];
34
        $voteFactories = $container->findTaggedServiceIds('expansion.vote_manager.vote');
35
        foreach ($voteFactories as $voteFactoryId => $data) {
36
            $voteFactorieReferences[] = new Reference($voteFactoryId);
37
        }
38
39
        $definition->replaceArgument('$voteFactories', $voteFactorieReferences);
40
    }
41
}