Completed
Pull Request — master (#90)
by Arnaud
02:31
created

DataProviderCompilerPass   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 27
loc 27
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 19 19 3

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 LAG\AdminBundle\DependencyInjection\CompilerPass;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9 View Code Duplication
class DataProviderCompilerPass implements CompilerPassInterface
10
{
11
    /**
12
     * Add the tagged data provider to the DataProviderFactory.
13
     *
14
     * @param ContainerBuilder $container
15
     */
16 3
    public function process(ContainerBuilder $container)
17
    {
18 3
        if (!$container->has('lag.admin.data_providers_factory')) {
19 2
            return;
20
        }
21
22 1
        $definition = $container->findDefinition('lag.admin.data_providers_factory');
23 1
        $taggedServices = $container->findTaggedServiceIds('data_provider');
24
25 1
        foreach ($taggedServices as $id => $tags) {
26 1
            $definition->addMethodCall(
27 1
                'addDataProvider',
28
                [
29 1
                    $id,
30 1
                    new Reference($id),
31
                ]
32
            );
33
        }
34 1
    }
35
}
36