RepositoryCompilerPass::process()   C
last analyzed

Complexity

Conditions 7
Paths 6

Size

Total Lines 30
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 7

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 30
ccs 16
cts 16
cp 1
rs 6.7272
cc 7
eloc 16
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('runopencode.exchange_rate.repository')) {
32 1
            return;
33
        }
34
35 3
        $repository = $container->getParameter('runopencode.exchange_rate.repository');
36
37 3
        if ($container->has($repository)) {
38 1
            $container->setAlias('runopencode.exchange_rate.repository', $repository);
39 1
            $container->findDefinition('runopencode.exchange_rate.repository')->setPublic(true);
40 1
            return;
41
        }
42
43 2
        foreach ($container->findTaggedServiceIds('runopencode.exchange_rate.repository') as $id => $tags) {
44
45 1
            foreach ($tags as $attributes) {
46
47 1
                if (isset($attributes['alias']) && $repository === $attributes['alias']) {
48 1
                    $definition = $container->findDefinition($id);
49 1
                    $container->setDefinition('runopencode.exchange_rate.repository', $definition);
50 1
                    $definition->setPublic(true);
51 1
                    return;
52
                }
53
            }
54
        }
55
56 1
        throw new ServiceNotFoundException(sprintf('Repository service "%s" does not exists.', $repository));
57
    }
58
}
59