Completed
Branch master (38bcb9)
by Matthew
02:36
created

BeanstalkdCompilerPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 15
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 3
nop 1
crap 12
1
<?php
2
3
namespace Dtc\QueueBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\Definition;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
class BeanstalkdCompilerPass implements CompilerPassInterface
11
{
12
    public function process(ContainerBuilder $container)
13
    {
14
        if ($container->hasParameter('dtc_queue.beanstalkd.host')) {
15
            $definition = new Definition(
16
                'Pheanstalk\\Pheanstalk',
17
                [$container->getParameter('dtc_queue.beanstalkd.host')]
18
            );
19
            $container->setDefinition('dtc_queue.beanstalkd', $definition);
20
            $definition = $container->getDefinition('dtc_queue.job_manager.beanstalkd');
21
            $definition->addMethodCall('setBeanstalkd', [new Reference('dtc_queue.beanstalkd')]);
22
            if ($container->hasParameter('dtc_queue.beanstalkd.tube')) {
23
                $definition->addMethodCall('setTube', [$container->getParameter('dtc_queue.beanstalkd.tube')]);
24
            }
25
        }
26
    }
27
}
28