Completed
Push — master ( 983b8f...66b3f3 )
by Nikola
03:24
created

RepositoryCompilerPass   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 0
loc 33
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C process() 0 27 7
1
<?php
2
/*
3
 * This file is part of the Exchange Rate Bundle, an RunOpenCode project.
4
 *
5
 * (c) 2017 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\Bundle\ExchangeRate\DependencyInjection\CompilerPass;
11
12
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
15
16
/**
17
 * Class RepositoryCompilerPass
18
 *
19
 * Repository compiler pass
20
 *
21
 * @package RunOpenCode\Bundle\ExchangeRate\DependencyInjection\CompilerPass
22
 */
23
class RepositoryCompilerPass implements CompilerPassInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28 4
    public function process(ContainerBuilder $container)
29
    {
30
31 4
        if (!$container->hasParameter('run_open_code.exchange_rate.repository')) {
32 1
            return;
33
        }
34
35 3
        $repository = $container->getParameter('run_open_code.exchange_rate.repository');
36
37 3
        if ($container->has($repository)) {
38 1
            $container->setAlias('run_open_code.exchange_rate.repository', $repository);
39 1
            return;
40
        }
41
42 2
        foreach ($container->findTaggedServiceIds('run_open_code.exchange_rate.repository') as $id => $tags) {
43
44 1
            foreach ($tags as $attributes) {
45
46 1
                if (isset($attributes['alias']) && $repository === $attributes['alias']) {
47 1
                    $container->setDefinition('run_open_code.exchange_rate.repository', $container->findDefinition($id));
48 1
                    return;
49
                }
50
            }
51
        }
52
53 1
        throw new ServiceNotFoundException(sprintf('Repository service "%s" does not exists.', $repository));
54
    }
55
}
56