ConsumeCommand::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 3
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