Test Failed
Pull Request — master (#39)
by Aleksandr
06:37
created

PurgeConsumerCommand::execute()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 14
c 2
b 0
f 0
nc 3
nop 2
dl 0
loc 25
ccs 0
cts 14
cp 0
crap 20
rs 9.7998
1
<?php
2
3
namespace OldSound\RabbitMqBundle\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\Console\Question\ConfirmationQuestion;
11
12
/**
13
 * Command to purge a queue
14
 */
15
class PurgeConsumerCommand extends Command
16 1
{
17
    protected function configure()
18 1
    {
19 1
        $this->addArgument('name', InputArgument::REQUIRED, 'Consumer Name')
20 1
             ->setDescription('Purge a consumer\'s queue')
21
             ->addOption('no-confirmation', null, InputOption::VALUE_NONE, 'Whether it must be confirmed before purging');
22 1
23 1
        $this->setName('rabbitmq:purge');
24
    }
25
26
    /**
27
     * @param InputInterface $input
28
     * @param OutputInterface $output
29
     *
30
     * @return int
31
     */
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        $noConfirmation = (bool) $input->getOption('no-confirmation');
35
36
        if (!$noConfirmation && $input->isInteractive()) {
37
            $question = new ConfirmationQuestion(
38
                sprintf(
39
                    '<question>Are you sure you wish to purge "%s" queue? (y/n)</question>',
40
                    $input->getArgument('name')
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('name') can also be of type string[]; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
                    /** @scrutinizer ignore-type */ $input->getArgument('name')
Loading history...
41
                ),
42
                false
43
            );
44
45
            if (!$this->getHelper('question')->ask($input, $output, $question)) {
46
                $output->writeln('<error>Purging cancelled!</error>');
47
48
                return 1;
49
            }
50
        }
51
52
        $this->consumer = $this->getContainer()
0 ignored issues
show
Bug Best Practice introduced by
The property consumer does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Bug introduced by
The method getContainer() does not exist on OldSound\RabbitMqBundle\...nd\PurgeConsumerCommand. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
        $this->consumer = $this->/** @scrutinizer ignore-call */ getContainer()

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
            ->get(sprintf($this->getConsumerService(), $input->getArgument('name')));
0 ignored issues
show
Bug introduced by
The method getConsumerService() does not exist on OldSound\RabbitMqBundle\...nd\PurgeConsumerCommand. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
            ->get(sprintf($this->/** @scrutinizer ignore-call */ getConsumerService(), $input->getArgument('name')));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
        $this->consumer->purge($input->getArgument('name'));
55
56
        return 0;
57
    }
58
}
59