DeleteIndexCommand::deleteIndex()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 15
cts 15
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 2
crap 1
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