Completed
Push — master ( 42f99d...2335a8 )
by Nikola
18:20 queued 03:48
created

RepositoryCompilerPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 13 3
A getKnownRepositoryAliases() 0 6 1
1
<?php
2
3
namespace RunOpenCode\Bundle\ExchangeRate\DependencyInjection\CompilerPass;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
8
class RepositoryCompilerPass implements CompilerPassInterface
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13
    public function process(ContainerBuilder $container)
14
    {
15
        $knownRepositories = $this->getKnownRepositoryAliases();
16
        $repositoryServiceId = $container->getParameter('run_open_code.exchange_rate.repository');
17
18
        $repositoryServiceId = isset($knownRepositories[$repositoryServiceId]) ? $knownRepositories[$repositoryServiceId] : $repositoryServiceId;
19
20
        if (!$container->hasDefinition($repositoryServiceId)) {
21
            throw new \RuntimeException(sprintf('Unknown repository service "%s" referenced in configuration.', $repositoryServiceId));
22
        }
23
24
        $container->setDefinition('run_open_code.exchange_rate.repository', $container->getDefinition($repositoryServiceId));
25
    }
26
27
    protected function getKnownRepositoryAliases()
28
    {
29
        return array(
30
            'file' => 'run_open_code.exchange_rate.repository.file_repository'
31
        );
32
    }
33
}
34