QueuePurgeCommand::execute()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 16

Duplication

Lines 8
Ratio 32 %

Importance

Changes 0
Metric Value
dl 8
loc 25
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 16
nc 2
nop 2
1
<?php
2
namespace Tavii\SQSJobQueueBundle\Command;
3
4
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
class QueuePurgeCommand extends  ContainerAwareCommand
0 ignored issues
show
Coding Style introduced by
Expected 1 space before "ContainerAwareCommand"; 2 found
Loading history...
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    protected function configure()
15
    {
16
        $this->setName('sqs_job_queue:queue-purge')
17
            ->setDescription('list queue')
18
            ->addArgument('queue', InputArgument::REQUIRED, 'queue name')
19
        ;
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function execute(InputInterface $input, OutputInterface $output)
26
    {
27
        $client = $this->getContainer()->get('sqs_job_queue.client');
28
        $queue = $input->getArgument('queue');
29
        $result = $client->getQueueUrl(array(
30
            'QueueName' => $queue
31
        ));
32
33
        $dialog = $this->getHelper('dialog');
34
        $ret = $dialog->askConfirmation(
35
            $output,
36
            "<question>{$queue} purge queue?[yes or no]</question> ",
37
            false
38
        );
39
40 View Code Duplication
        if ($ret) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
            $client->purgeQueue(array(
42
                'QueueUrl' => $result['QueueUrl']
43
            ));
44
            $output->writeln('<info>pugrge queue url</info>: '. $result['QueueUrl']);
45
        } else {
46
            $output->writeln('cancel purge...');
47
        }
48
49
    }
50
}