Passed
Push — master ( e31e38...b36f9b )
by Andreas
16:51
created

indexerPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 26
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 14 3
A __construct() 0 3 1
1
<?php
2
namespace midcom\dependencyInjection;
3
4
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use midcom_config;
7
use Symfony\Component\DependencyInjection\Definition;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
class indexerPass implements CompilerPassInterface
11
{
12
    /**
13
     * @var midcom_config
14
     */
15
    private $config;
16
17 1
    public function __construct(midcom_config $config)
18
    {
19 1
        $this->config = $config;
20 1
    }
21
22 1
    public function process(ContainerBuilder $container)
23
    {
24 1
        if ($class = $this->config->get('indexer_backend')) {
25 1
            if (strpos($class, '_') === false) {
26
                // Built-in backend called using the shorthand notation
27 1
                $class = "midcom_services_indexer_backend_" . $class;
28
            }
29
30 1
            $container->setDefinition('indexer.backend', new Definition($class));
31 1
            $backend = $container->getDefinition('indexer');
32 1
            $backend->addArgument(new Reference('indexer.backend'));
33
34 1
            $container->getDefinition('event_dispatcher')
35 1
                ->addMethodCall('addSubscriber', [new Reference('indexer')]);
36
        }
37
    }
38
}