ConsumerCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 0
loc 35
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 11 1
A execute() 0 14 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