Completed
Push — master ( abc735...f26a97 )
by Valentin
16s queued 11s
created

PheanstalkExtension::configureLocator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Pyrowman\PheanstalkBundle\DependencyInjection;
4
5
use Pyrowman\PheanstalkBundle\DataCollector\PheanstalkDataCollector;
6
use Pyrowman\PheanstalkBundle\Exceptions\PheanstalkException;
7
use Pyrowman\PheanstalkBundle\Listener\PheanstalkLogListener;
8
use Pyrowman\PheanstalkBundle\PheanstalkLocator;
9
use Symfony\Component\Config\FileLocator;
10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11
use Symfony\Component\DependencyInjection\Definition;
12
use Symfony\Component\DependencyInjection\Loader;
13
use Symfony\Component\DependencyInjection\Reference;
14
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
15
16
/**
17
 * This is the class that loads and manages your bundle configuration.
18
 *
19
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
20
 */
21
class PheanstalkExtension extends Extension
22
{
23
    /**
24
     * {@inheritDoc}
25
     */
26 11
    public function load(array $configs, ContainerBuilder $container)
27
    {
28 11
        $configuration = new Configuration();
29 11
        $config        = $this->processConfiguration($configuration, $configs);
30
31 11
        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
32 11
        $loader->load('services.xml');
33 11
        $loader->load('commands.xml');
34
35 11
        $this->configureLocator($container, $config);
36 11
        $this->configureLogListener($container, $config);
37 11
        $this->configureProfiler($container, $config);
38
    }
39
40
    /**
41
     * @param ContainerBuilder $container
42
     * @param array            $config
43
     */
44 11
    private function configureLogListener(ContainerBuilder $container, array $config): void
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

44
    private function configureLogListener(ContainerBuilder $container, /** @scrutinizer ignore-unused */ array $config): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
    {
46 11
        if (false === $container->has('logger')) {
47 10
            return;
48
        }
49
        // Create a connection locator that will reference all existing connection
50 1
        $definition = new Definition(PheanstalkLogListener::class);
51 1
        $definition->addArgument(new Reference(PheanstalkLocator::class));
52 1
        $definition->addTag('kernel.event_subscriber');
53 1
        $definition->addTag('monolog.logger', [
54 1
            'channel' => 'pheanstalk',
55
        ]);
56 1
        $definition->addMethodCall('setLogger', [
57 1
            new Reference('logger')
58
        ]);
59 1
        $container->setDefinition('pheanstalk.listener.log', $definition)->setPublic(true);
60 1
        $container->setAlias(PheanstalkLogListener::class, 'pheanstalk.listener.log');
61
    }
62
    /**
63
     * @param ContainerBuilder $container
64
     * @param array            $config
65
     */
66 11
    private function configureLocator(ContainerBuilder $container, array $config): void
67
    {
68
        // Create a connection locator that will reference all existing connection
69 11
        $connectionLocatorDef = new Definition(PheanstalkLocator::class);
70 11
        $connectionLocatorDef->setPublic(true);
71 11
        $container->setDefinition('pheanstalk.pheanstalk_locator', $connectionLocatorDef);
72 11
        $container->setAlias(PheanstalkLocator::class, 'pheanstalk.pheanstalk_locator');
73 11
        $container->setParameter('pheanstalk.pheanstalks', $config['pheanstalks']);
74
    }
75
76
    /**
77
     * Configures the profiler data collector.
78
     *
79
     * @param ContainerBuilder $container Container
80
     * @param array            $config    Configuration
81
     */
82 11
    private function configureProfiler(ContainerBuilder $container, array $config): void
83
    {
84 11
        if (false === $config['profiler']['enabled']) {
85 1
            return;
86
        }
87
        // Setup the data collector service for Symfony profiler
88 10
        $dataCollectorDef = new Definition(PheanstalkDataCollector::class);
89 10
        $dataCollectorDef->setPublic(true);
90 10
        $dataCollectorDef->addTag('data_collector', ['id' => 'pheanstalk', 'template' => $config['profiler']['template']]);
91 10
        $dataCollectorDef->addArgument(new Reference('pheanstalk.pheanstalk_locator'));
92 10
        $container->setDefinition('pheanstalk.data_collector', $dataCollectorDef);
93 10
        $container->setAlias(PheanstalkDataCollector::class, 'pheanstalk.data_collector');
94
    }
95
}
96