Completed
Push — master ( 89b849...9da0e2 )
by GBProd
02:23
created

ListIndexCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 4
lcom 0
cbo 6
dl 13
loc 39
ccs 19
cts 19
cp 1
rs 10
c 2
b 1
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 9 1
A execute() 13 13 2
A extractIndices() 0 6 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\ElasticaExtraBundle\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 list indices
12
 *
13
 * @author gbprod <[email protected]>
14
 */
15
class ListIndexCommand extends ElasticaAwareCommand
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 2
    protected function configure()
21
    {
22 2
        $this
23 2
            ->setName('elasticsearch:index:list')
24 2
            ->setDescription('Index list')
25 2
            ->addOption('pattern', '', InputOption::VALUE_REQUIRED, 'Index name filter pattern', null)
26 2
            ->addOption('client', null, InputOption::VALUE_REQUIRED, 'Client to use (if not default)', null)
27
        ;
28 2
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 2 View Code Duplication
    protected function execute(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...
34
    {
35 2
        $client = $this->getClient($input->getOption('client'));
36
37 2
        $uri = sprintf('_cat/indices/%s?h=i', $input->getOption('pattern'));
38 2
        $response = $client->request($uri);
39
40 2
        $indices = $this->extractIndices($response->getData()['message']);
41
42 2
        foreach ($indices as $index) {
43 2
            $output->writeln($index);
44 2
        }
45 2
    }
46
47 2
    private function extractIndices($data)
48
    {
49 2
        $lines = preg_split('#\R#', $data);
50
51 2
        return array_map('trim', $lines);
52
    }
53
}
54