Completed
Push — master ( 5524a5...bc12da )
by Jeroen
54:06 queued 48:17
created

SearchProviderCompilerPass::process()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18

Duplication

Lines 18
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 4.0119

Importance

Changes 0
Metric Value
dl 18
loc 18
ccs 10
cts 11
cp 0.9091
rs 9.6666
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 4.0119
1
<?php
2
3
namespace Kunstmaan\SearchBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
/**
10
 * CompilerPass class for SearchProviders
11
 *
12
 * Will find all services tagged "kunstmaan_search.searchprovider" and will add them to the chain with their alias.
13
 */
14 View Code Duplication
class SearchProviderCompilerPass implements CompilerPassInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
15
{
16
    /**
17
     * @param ContainerBuilder $container
18
     */
19 1
    public function process(ContainerBuilder $container)
20
    {
21 1
        if (!$container->hasDefinition('kunstmaan_search.search_provider_chain')) {
22
            return;
23
        }
24
25 1
        $definition = $container->getDefinition('kunstmaan_search.search_provider_chain');
26 1
        $taggedServices = $container->findTaggedServiceIds('kunstmaan_search.search_provider');
27
28 1
        foreach ($taggedServices as $id => $tagAttributes) {
29 1
            foreach ($tagAttributes as $attributes) {
30 1
                $definition->addMethodCall(
31 1
                    'addProvider',
32 1
                    array(new Reference($id), $attributes['alias'])
33
                );
34
            }
35
        }
36 1
    }
37
}
38