RpcServerCommand::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 8
c 1
b 1
f 0
nc 2
nop 2
dl 0
loc 14
ccs 0
cts 7
cp 0
crap 6
rs 10
1
<?php
2
3
namespace OldSound\RabbitMqBundle\Command;
4
5
use Symfony\Component\Console\Input\InputOption;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class RpcServerCommand extends BaseRabbitMqCommand
11
{
12
    protected function configure(): void
13
    {
14
        parent::configure();
15
16
        $this
17
            ->setName('rabbitmq:rpc-server')
18
            ->setDescription('Start an RPC server')
19
            ->addArgument('name', InputArgument::REQUIRED, 'Server Name')
20
            ->addOption('messages', 'm', InputOption::VALUE_OPTIONAL, 'Messages to consume', '0')
21
            ->addOption('debug', 'd', InputOption::VALUE_OPTIONAL, 'Debug mode', false)
22
        ;
23
    }
24
25
    /**
26
     * Executes the current command.
27
     *
28
     * @param InputInterface  $input  An InputInterface instance
29
     * @param OutputInterface $output An OutputInterface instance
30
     *
31
     * @return integer 0 if everything went fine, or an error code
32
     *
33
     * @throws \InvalidArgumentException When the number of messages to consume is less than 0
34
     */
35
    protected function execute(InputInterface $input, OutputInterface $output): int
36
    {
37
        define('AMQP_DEBUG', (bool) $input->getOption('debug'));
38
        $amount = (int)$input->getOption('messages');
39
40
        if (0 > $amount) {
41
            throw new \InvalidArgumentException("The -m option should be null or greater than 0");
42
        }
43
44
        $this->getContainer()
45
               ->get(sprintf('old_sound_rabbit_mq.%s_server', $input->getArgument('name')))
46
               ->start($amount);
47
48
        return 0;
49
    }
50
}
51