DictionaryTracePass   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 14 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Knp\DictionaryBundle\DependencyInjection\Compiler;
6
7
use Knp\DictionaryBundle\DataCollector\DictionaryDataCollector;
8
use Knp\DictionaryBundle\Dictionary\Traceable;
9
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11
use Symfony\Component\DependencyInjection\Definition;
12
use Symfony\Component\DependencyInjection\Reference;
13
14
final class DictionaryTracePass implements CompilerPassInterface
15
{
16
    public function process(ContainerBuilder $containerBuilder): void
17
    {
18
        if (!$containerBuilder->has(DictionaryDataCollector::class)) {
19
            return;
20
        }
21
22
        foreach (array_keys($containerBuilder->findTaggedServiceIds(DictionaryRegistrationPass::TAG_DICTIONARY)) as $id) {
23
            $serviceId  = \sprintf('%s.%s.traceable', $id, md5($id));
24
            $dictionary = new Reference(\sprintf('%s.inner', $serviceId));
25
            $traceable  = new Definition(Traceable::class, [$dictionary, new Reference(DictionaryDataCollector::class)]);
26
27
            $traceable->setDecoratedService($id);
28
29
            $containerBuilder->setDefinition($serviceId, $traceable);
30
        }
31
    }
32
}
33