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

RepositoryCompilerPass::process()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 27
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 13
cts 13
cp 1
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 13
nc 6
nop 1
crap 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