Completed
Push — 1.0 ( c155d9...973d0d )
by David
03:18
created

ConsumeCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Mouf\AmqpClient\Commands;
4
5
use Mouf\AmqpClient\ConsumerService;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class ConsumeCommand extends Command
12
{
13
    /**
14
     * @var ConsumerService
15
     */
16
    private $consumerService;
17
18
    /**
19
     * ConsumeCommand constructor.
20
     */
21
    public function __construct(ConsumerService $consumerService, $commandName = 'amqp:consume', $description = null)
22
    {
23
        parent::__construct($commandName);
24
        $this->setDescription($description ?: 'Listen to messages from the AMQP bus (RabbitMQ)');
25
        $this->consumerService = $consumerService;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected function configure()
32
    {
33
        $this
34
            ->addOption('onlyone', 'o', InputOption::VALUE_NONE, 'Receives only one message and stop listening');
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    protected function execute(InputInterface $input, OutputInterface $output)
41
    {
42
        $this->consumerService->run($input->getOption('onlyone'));
43
    }
44
}
45