AddProvidersPass   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 21
ccs 8
cts 9
cp 0.8889
rs 10
c 0
b 0
f 0

1 Method

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