ConsumerCommand::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 2
crap 1
1
<?php
2
3
namespace MyOnlineStore\Bundle\RabbitMqManagerBundle\Command;
4
5
use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface;
6
use PhpAmqpLib\Message\AMQPMessage;
7
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Input\InputOption;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
final class ConsumerCommand extends ContainerAwareCommand
14
{
15
    /**
16
     * @inheritdoc
17
     */
18 1
    protected function configure()
19
    {
20 1
        $this
21 1
            ->addArgument('event', InputArgument::REQUIRED)
22 1
            ->addOption('callback', null, InputOption::VALUE_REQUIRED, 'Callback service name')
23 1
            ->setName('rabbitmq-manager:consumer')
24 1
            ->setDescription('
25
This console command can only be used in combination with the rabbitmq-cli-consumer.
26
https://github.com/ricbra/rabbitmq-cli-consumer
27 1
');
28 1
    }
29
30
    /**
31
     * @inheritdoc
32
     */
33 1
    protected function execute(InputInterface $input, OutputInterface $output)
34
    {
35 1
        $data = json_decode(gzuncompress(base64_decode($input->getArgument('event'))), true);
36
37
        /** @var ConsumerInterface $service */
38 1
        $service = $this->getContainer()->get($input->getOption('callback'));
39
40 1
        $service->execute(
41 1
            new AMQPMessage(
42 1
                $data['body'],
43 1
                $data['properties']
44 1
            )
45 1
        );
46 1
    }
47
}
48