RegisterConverterCompilerPass   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 22
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 16 5
1
<?php
2
3
namespace Toothless\LazyImageBundle\DependencyInjection\CompilerPass;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
/**
10
 * Class RegisterConverterCompilerPass
11
 *
12
 * Register services by adding the following tags :
13
 * ``̀
14
 * - {name: "toothless.lazy_image.converter" }
15
 * ```
16
 */
17
class RegisterConverterCompilerPass implements CompilerPassInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22 6
    public function process(ContainerBuilder $container)
23
    {
24 6
        if (!$container->hasDefinition('toothless.lazy_image.converter_manager')) {
25 1
            return;
26
        }
27
28 5
        $definition = $container->getDefinition('toothless.lazy_image.converter_manager');
29 5
        $services = $container->findTaggedServiceIds('toothless.lazy_image.converter');
30
31 5
        foreach ($services as $id => $tags) {
32 4
            foreach ($tags as $attributes) {
33 4
                $name = isset($attributes['alias']) ? $attributes['alias'] : $id;
34 4
                $definition->addMethodCall('addConverter', [$name, new Reference($id)]);
35 4
            }
36 5
        }
37 5
    }
38
}
39