Completed
Push — master ( 7a257e...017c35 )
by Leny
109:58 queued 102:36
created

ViewReferenceConnectorCompilerPass::process()   C

Complexity

Conditions 8
Paths 36

Size

Total Lines 33
Code Lines 21

Duplication

Lines 8
Ratio 24.24 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 8
loc 33
rs 5.3846
cc 8
eloc 21
nc 36
nop 1
1
<?php
2
3
namespace Victoire\Bundle\ViewReferenceBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
8
class ViewReferenceConnectorCompilerPass implements CompilerPassInterface
9
{
10
    public function process(ContainerBuilder $container)
11
    {
12
        $viewReferenceManagers = $container->findTaggedServiceIds(
13
            'view_reference.manager'
14
        );
15
16
        $viewReferenceRepositories = $container->findTaggedServiceIds(
17
            'view_reference.repository'
18
        );
19
        $connectors = [];
20
        $connectorType = $container->getParameter('victoire_view_reference.connector.type');
21
        foreach ($viewReferenceManagers as $id => $tags) {
22
            foreach ($tags as $attributes) {
23
                $connectors[$attributes['connector']]['manager'] = $id;
24
            }
25
        }
26
        foreach ($viewReferenceRepositories as $id => $tags) {
27
            foreach ($tags as $attributes) {
28
                $connectors[$attributes['connector']]['repository'] = $id;
29
            }
30
        }
31
        if (!isset($connectorType)) {
32
            throw new \Exception('No manager and repository found to have '.$connectorType.' connector.');
33
        }
34 View Code Duplication
        if (!isset($connectors[$connectorType]['manager'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
            throw new \Exception('No manager found to have '.$connectorType.' connector.');
36
        }
37 View Code Duplication
        if (!isset($connectors[$connectorType]['repository'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
            throw new \Exception('No repository found to have '.$connectorType.' connector.');
39
        }
40
        $container->setAlias('victoire_view_reference.connector.manager', $connectors[$connectorType]['manager']);
41
        $container->setAlias('victoire_view_reference.connector.repository', $connectors[$connectorType]['repository']);
42
    }
43
}
44