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

DeleteCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 7
ccs 0
cts 6
cp 0
crap 2
rs 10
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 delete a queue
14
 */
15
class DeleteCommand extends Command
16
{
17
    protected function configure()
18
    {
19
        $this->addArgument('name', InputArgument::REQUIRED, 'Consumer Name')
20
             ->setDescription('Delete a consumer\'s queue')
21
             ->addOption('no-confirmation', null, InputOption::VALUE_NONE, 'Whether it must be confirmed before deleting');
22
23
        $this->setName('rabbitmq:delete');
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 delete "%s" consumer\'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>Deletion 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\Command\DeleteCommand. ( 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\Command\DeleteCommand. ( 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->delete();
55
56
        return 0;
57
    }
58
}
59