ClientCompilerPass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 26 4
1
<?php
2
3
namespace Guzzle\ConfigOperationsBundle\DependencyInjection\CompilerPass;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\Definition;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
/**
11
 * Compiler pass that will add our definitions to Guzzle clients.
12
 *
13
 * @author Pierre Rolland <[email protected]>
14
 */
15
class ClientCompilerPass implements CompilerPassInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function process(ContainerBuilder $container)
21
    {
22
        $taggedServices = $container->findTaggedServiceIds(
23
            'guzzle.client'
24
        );
25
26
        $definitions = [];
27
        foreach ($taggedServices as $id => $tags) {
28
            foreach ($tags as $attributes) {
29
                $definitionId = sprintf('guzzle_client.%s', $attributes['alias']);
30
                if (!$container->has($definitionId)) {
31
                    $definition = new Definition();
32
                    $definition->setClass('Guzzle\ConfigOperationsBundle\GuzzleClient');
33
                    $definition->setFactory([
34
                        new Reference('guzzle_config_operations.factory'),
35
                        'getClient'
36
                    ]);
37
                    $definition->setPublic(true);
38
                    $definition->addArgument($id);
39
                    $definitions[$definitionId] = $definition;
40
                }
41
            }
42
        }
43
44
        $container->addDefinitions($definitions);
45
    }
46
}
47