DeleteIndexCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 18.52 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 10
loc 54
ccs 35
cts 35
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 10 10 1
A execute() 0 8 2
A deleteIndex() 0 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\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
/**
11
 * Command to delete index
12
 *
13
 * @author gbprod <[email protected]>
14
 */
15
class DeleteIndexCommand extends ElasticsearchAwareCommand
16
{
17 View Code Duplication
    protected function configure()
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...
18
    {
19 1
        $this
20 1
            ->setName('elasticsearch:index:delete')
21 1
            ->setDescription('delete index from configuration')
22 1
            ->addArgument('index', InputArgument::REQUIRED, 'Which index ?')
23 1
            ->addOption('force', null, InputOption::VALUE_NONE, 'Set this parameter to execute this action')
24 1
            ->addOption('client', null, InputOption::VALUE_REQUIRED, 'Client to use (if not default)', 'default')
25
        ;
26 1
    }
27
28
    protected function execute(InputInterface $input, OutputInterface $output)
29
    {
30 1
        if ($input->getOption('force')) {
31 1
            $this->deleteIndex($input, $output);
32 1
        } else {
33 1
            $this->displayWarningMassage($input, $output);
34
        }
35 1
    }
36
37 1
    private function deleteIndex(InputInterface $input, OutputInterface $output)
38
    {
39 1
        $client = $this->getClient($input->getOption('client'));
40 1
        $index  = $input->getArgument('index');
41
42 1
        $output->writeln(sprintf(
43 1
            '<info>Deleting index <comment>%s</comment> for client <comment>%s</comment>...</info>',
44 1
            $index,
45 1
            $input->getOption('client')
46 1
        ));
47
48 1
        $handler = $this
49 1
            ->getContainer()
50 1
            ->get('gbprod.elasticsearch_extra.delete_index_handler')
51 1
        ;
52
53 1
        $handler->handle($client, $index);
54
55 1
        $output->writeln('done');
56 1
    }
57
58
    private function displayWarningMassage(InputInterface $input, OutputInterface $output)
59
    {
60 1
        $output->writeln('<error>ATTENTION</error>');
61 1
        $output->writeln(sprintf(
62 1
            '<info>Will delete the index <comment>%s</comment> on client <comment>%s</comment>.</info>',
63 1
            $input->getOption('client'),
64 1
            $input->getArgument('index')
65 1
        ));
66 1
        $output->writeln('Run the operation with --force to execute');
67 1
    }
68
}
69