Completed
Push — master ( 709dbb...f12a68 )
by Tobias
09:11
created

ProfilerPass   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 17 3
1
<?php
2
3
/*
4
 * This file is part of the BazingaGeocoderBundle package.
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @license    MIT License
9
 */
10
11
namespace Bazinga\GeocoderBundle\DependencyInjection\Compiler;
12
13
use Bazinga\GeocoderBundle\DataCollector\GeocoderDataCollector;
14
use Bazinga\GeocoderBundle\DataCollector\ProfilingProvider;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Reference;
18
19
/**
20
 * Add Profiling on all providers with that 'bazinga_geocoder.provider'.
21
 *
22
 * @author Tobias Nyholm <[email protected]>
23
 */
24
class ProfilerPass implements CompilerPassInterface
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function process(ContainerBuilder $container)
30
    {
31
        if (!$container->hasDefinition(GeocoderDataCollector::class)) {
32
            return;
33
        }
34
35
        $dataCollector = $container->getDefinition(GeocoderDataCollector::class);
36
37
        foreach ($container->findTaggedServiceIds('bazinga_geocoder.provider') as $providerId => $attributes) {
38
            $container->register($providerId.'.debug', ProfilingProvider::class)
39
                ->setDecoratedService($providerId)
40
                ->setArguments([
41
                    new Reference($providerId.'.debug.inner'),
42
                ]);
43
            $dataCollector->addMethodCall('addInstance', [new Reference($providerId)]);
44
        }
45
    }
46
}
47