Completed
Push — master ( 7c5f10...b4e87f )
by Tomasz
05:55
created

RabbitMqWorkerRunner::getContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Gendoria\CommandQueueRabbitMqDriverBundle\Worker;
4
5
use Gendoria\CommandQueue\Worker\WorkerRunnerInterface;
6
use InvalidArgumentException;
7
use Symfony\Bundle\FrameworkBundle\Console\Application;
8
use Symfony\Component\Console\Input\ArrayInput;
9
use Symfony\Component\Console\Output\NullOutput;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\DependencyInjection\ContainerInterface;
12
use Symfony\Component\HttpKernel\HttpKernelInterface;
13
14
/**
15
 * Description of RabbitMqWorkerRunner
16
 *
17
 * @author Tomasz Struczyński <[email protected]>
18
 */
19
class RabbitMqWorkerRunner implements WorkerRunnerInterface
20
{
21
    /**
22
     * Container.
23
     * 
24
     * @var ContainerInterface
25
     */
26
    private $container;
27
    
28
    /**
29
     * Set container.
30
     * 
31
     * @param ContainerInterface $container
32
     */
33 3
    function setContainer(ContainerInterface $container)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
34
    {
35 3
        $this->container = $container;
36 3
    }
37
    
38
    /**
39
     * Get container.
40
     * 
41
     * @return ContainerInterface|null
42
     */
43 1
    function getContainer()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
44
    {
45 1
        return $this->container;
46
    }
47
    
48
    /**
49
     * {@inheritdoc}
50
     */
51 3
    public function run(array $options, OutputInterface $output = null)
52
    {
53 3
        if (empty($options['consumer_name'])) {
54 1
            throw new InvalidArgumentException("Options array has to contain consumer_name.");
55
        }
56 2
        if (!$output) {
57 2
            $output = new NullOutput();
58 2
        }
59
        /* @var $kernel HttpKernelInterface */
60 2
        $kernel = $this->container->get('kernel');
61 2
        $application = new Application($kernel);
0 ignored issues
show
Documentation introduced by
$kernel is of type object<Symfony\Component...el\HttpKernelInterface>, but the function expects a object<Symfony\Component...Kernel\KernelInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
62 2
        $application->setAutoExit(false);
63 2
        $input = new ArrayInput(array(
64 2
            'command' => 'rabbitmq:consumer',
65 2
            '-w' => null,
66 2
            'name' => !empty($options['reschedule']) ? $options['consumer_name'].'_reschedule_delayed' : $options['consumer_name'],
67 2
        ));
68 2
        $application->run($input, $output);
69 2
    }
70
71
}
72