MetricsCollectorPass   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 35
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 27 7
1
<?php
2
3
namespace Flagbit\Bundle\MetricsBundle\DependencyInjection\Compiler;
4
5
use Flagbit\Bundle\MetricsBundle\Provider\ProviderInvoker;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
class MetricsCollectorPass implements CompilerPassInterface
11
{
12
    /**
13
     * Add tagged metrics.provider services to flagbit_metrics.collector service
14
     *
15
     * @param ContainerBuilder $container
16
     */
17 2
    public function process(ContainerBuilder $container)
18
    {
19 2
        if (false === $container->hasDefinition(ProviderInvoker::class)) {
20
            return;
21
        }
22
23 2
        $definition = $container->getDefinition(ProviderInvoker::class);
24
25 2
        foreach ($container->findTaggedServiceIds('metrics.provider') as $id => $tags) {
26 2
            $collectors = [];
27 2
            foreach($tags as $attributes) {
28 2
                if (!isset($attributes['collector'])) {
29 1
                    throw new \InvalidArgumentException(sprintf(
30 1
                            'Metrics provider service "%s" must have an collector attribute in oder to specify a collector',
31 1
                            $id
32
                        ));
33
                }
34 1
                if ($container->hasDefinition('beberlei_metrics.collector.' . $attributes['collector'])) {
35 1
                    $collectors[] = new Reference('beberlei_metrics.collector.' . $attributes['collector']);
36
                }
37
            }
38
39 1
            if (!empty($collectors)) {
40 1
                $definition->addMethodCall('addMetricsProvider', [new Reference($id), $collectors]);
41
            }
42
        }
43 1
    }
44
}
45