Completed
Push — master ( d5f83d...983b8f )
by Nikola
03:31
created

RepositoryCompilerPass::process()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 0
cts 17
cp 0
rs 8.6737
c 0
b 0
f 0
cc 6
eloc 11
nc 5
nop 1
crap 42
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
    public function process(ContainerBuilder $container)
29
    {
30
        $repository = $container->getParameter('run_open_code.exchange_rate.repository');
31
32
        if ($container->hasDefinition($repository)) {
33
            $container->setDefinition('run_open_code.exchange_rate.repository', $repository);
34
            return;
35
        }
36
37
        foreach ($container->findTaggedServiceIds('run_open_code.exchange_rate.repository') as $id => $tags) {
38
39
            foreach ($tags as $attributes) {
40
                
41
                if (isset($attributes['alias']) && $repository === $attributes['alias']) {
42
                    $container->setDefinition('run_open_code.exchange_rate.repository', $id);
0 ignored issues
show
Documentation introduced by
$id is of type integer|string, but the function expects a object<Symfony\Component...cyInjection\Definition>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
43
                    return;
44
                }
45
            }
46
        }
47
48
        throw new ServiceNotFoundException(sprintf('Repository service "%s" does not exists.', $repository));
49
    }
50
}
51