Test Setup Failed
Pull Request — master (#8)
by
unknown
12:33
created

CompilerPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 34
ccs 0
cts 16
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 12 1
A getServiceReference() 0 6 4
1
<?php
2
3
namespace MovingImage\Bundle\VMProApiBundle\DependencyInjection;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
class CompilerPass implements CompilerPassInterface
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public function process(ContainerBuilder $container)
15
    {
16
        $clientDefinition = $container->getDefinition('vmpro_api.client');
17
18
        $logger = $this->getServiceReference($container, $container->getParameter('vm_pro_api_logger'));
19
        $cacheAdapter = $this->getServiceReference($container, $container->getParameter('vm_pro_api_cache_adapter'));
20
        $cacheTtl = $container->getParameter('vm_pro_api_cache_ttl');
21
22
        $clientDefinition->setArgument(2, $logger);
23
        $clientDefinition->setArgument(3, $cacheAdapter);
24
        $clientDefinition->setArgument(4, $cacheTtl);
25
    }
26
27
    /**
28
     * Returns a reference to a service, if that service exists in the container.
29
     * Otherwise returns null.
30
     *
31
     * @param ContainerBuilder $container
32
     * @param string           $serviceId
33
     *
34
     * @return Reference|null
35
     */
36
    private function getServiceReference(ContainerBuilder $container, $serviceId)
37
    {
38
        if ($serviceId && ($container->hasDefinition($serviceId) || $container->hasAlias($serviceId))) {
39
            return new Reference($serviceId);
40
        }
41
    }
42
}
43