QueuePurgeCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 19.05 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 8
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
B execute() 8 25 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}