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

ViewReferenceConnectorCompilerPass   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 36
Duplicated Lines 22.22 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 8
c 2
b 1
f 0
lcom 0
cbo 1
dl 8
loc 36
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C process() 8 33 8

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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