ListCompilerPass   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 12
c 1
b 0
f 0
dl 0
loc 33
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 8 1
A buildLocator() 0 10 2
1
<?php
2
3
namespace Povs\ListerBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
9
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
10
use Symfony\Component\DependencyInjection\Reference;
11
12
/**
13
 * @author Povilas Margaiatis <[email protected]>
14
 */
15
class ListCompilerPass implements CompilerPassInterface
16
{
17
    /**
18
     * @inheritdoc
19
     */
20 1
    public function process(ContainerBuilder $container): void
21
    {
22 1
        $this->buildLocator($container, 'povs_lister.list', '.povs_lister.locator.list');
23 1
        $this->buildLocator($container, 'povs_lister.query_type', '.povs_lister.locator.query_type');
24 1
        $this->buildLocator($container, 'povs_lister.field_type', '.povs_lister.locator.field_type');
25 1
        $this->buildLocator($container, 'povs_lister.list_type', '.povs_lister.locator.list_type');
26 1
        $this->buildLocator($container, 'povs_lister.filter_type', '.povs_lister.locator.filter_type');
27 1
        $this->buildLocator($container, 'povs_lister.selector_type', '.povs_lister.locator.selector_type');
28
    }
29
30
    /**
31
     * @param ContainerBuilder $container
32
     * @param string           $tag       tag name of the services
33
     * @param string           $locator   fully qualified class name
34
     *
35
     * @throws InvalidArgumentException
36
     * @throws ServiceNotFoundException
37
     */
38 1
    private function buildLocator(ContainerBuilder $container, string $tag, string $locator): void
39
    {
40 1
        $ref = [];
41
42 1
        foreach ($container->findTaggedServiceIds($tag, true) as $id => $tags) {
43 1
            $ref[$id] = new ServiceClosureArgument(new Reference($id));
44
        }
45
46 1
        $locatorDef = $container->getDefinition($locator);
47 1
        $locatorDef->setArgument(0, $ref);
48
    }
49
}
50