Completed
Push — master ( 4ef090...a7a684 )
by GBProd
02:22
created

DeleteIndexCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 29.85 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 5
dl 20
loc 67
ccs 45
cts 45
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 23 1
A execute() 0 8 2
A deleteIndex() 20 20 1
A displayWarningMassage() 0 10 1

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
3
namespace GBProd\ElasticsearchExtraBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
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
11
/**
12
 * Command to delete index
13
 * 
14
 * @author gbprod <[email protected]>
15
 */
16
class DeleteIndexCommand extends ContainerAwareCommand
17
{
18
    protected function configure()
19
    {
20 1
        $this
21 1
            ->setName('elasticsearch:index:delete')
22 1
            ->setDescription('delete index from configuration')
23 1
            ->addArgument(
24 1
                'client_id',
25 1
                InputArgument::REQUIRED,
26
                'Which client ?'
27 1
            )
28 1
            ->addArgument(
29 1
                'index_id',
30 1
                InputArgument::REQUIRED,
31
                'Which index ?'
32 1
            )
33 1
            ->addOption(
34 1
                'force', 
35 1
                null, 
36 1
                InputOption::VALUE_NONE, 
37 1
                'Set this parameter to execute this action'
38 1
            )
39
        ;
40 1
    }
41
42 1
    protected function execute(InputInterface $input, OutputInterface $output)
43
    {
44 1
        if ($input->getOption('force')) {
45 1
            $this->deleteIndex($input, $output);
46 1
        } else {
47 1
            $this->displayWarningMassage($input, $output);
48
        }
49 1
    }
50
    
51 View Code Duplication
    private function deleteIndex(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
52
    {
53 1
        $clientId = $input->getArgument('client_id');
54 1
        $indexId  = $input->getArgument('index_id');
55
        
56 1
        $output->writeln(sprintf(
57 1
            '<info>Deleting index "%s" for client "%s"...</info>',
58 1
            $indexId,
59
            $clientId
60 1
        ));
61
        
62 1
        $handler = $this
63 1
            ->getContainer()
64 1
            ->get('gbprod.elasticsearch_extra.delete_index_handler')
65 1
        ;
66
        
67 1
        $handler->handle($clientId, $indexId);
68
        
69 1
        $output->writeln('<info>done</info>');
70 1
    }
71
    
72
    private function displayWarningMassage(InputInterface $input, OutputInterface $output)
73
    {
74 1
        $output->writeln('<error>ATTENTION</error>');
75 1
        $output->writeln(sprintf(
76 1
            '<info>Would drop the index <comment>%s</comment> on client <comment>%s</comment>.</info>', 
77 1
            $input->getArgument('client_id'),
78 1
            $input->getArgument('index_id')
79 1
        ));
80 1
        $output->writeln('Run the operation with --force to execute');
81
    }
82
}