PutIndexMappingsCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 28.21 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 4
dl 11
loc 39
ccs 27
cts 27
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B execute() 0 24 2
A configure() 11 11 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 put index mappings
12
 *
13
 * @author gbprod <[email protected]>
14
 */
15
class PutIndexMappingsCommand extends ElasticaAwareCommand
16
{
17 2 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 2
        $this
20 2
            ->setName('elasticsearch:index:put_mappings')
21 2
            ->setDescription('Put index mappings from configuration')
22 2
            ->addArgument('index', InputArgument::REQUIRED, 'Which index ?')
23 2
            ->addArgument('type', InputArgument::REQUIRED, 'Which type ?')
24 2
            ->addOption('client', null, InputOption::VALUE_REQUIRED, 'Client to use (if not default)', null)
25 2
            ->addOption('alias', null, InputOption::VALUE_REQUIRED, 'Index configuration to use (if not the same as index argument)', null)
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 139 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
26
        ;
27 2
    }
28
29 2
    protected function execute(InputInterface $input, OutputInterface $output)
30
    {
31 2
        $client = $this->getClient($input->getOption('client'));
32 2
        $index  = $input->getArgument('index');
33 2
        $type   = $input->getArgument('type');
34 2
        $alias  = $input->getOption('alias') ?: $index;
35
36 2
        $output->writeln(sprintf(
37
            '<info>Put type <comment>%s</comment> mappings for index <comment>%s</comment> '.
38 2
            'client <comment>%s</comment>...</info>',
39 2
            $type,
40 2
            $index,
41 2
            $input->getOption('client')
42 2
        ));
43
44 2
        $handler = $this
45 2
            ->getContainer()
46 2
            ->get('gbprod.elastica_extra.put_index_mappings_handler')
47 2
        ;
48
49 2
        $handler->handle($client, $index, $type, $alias);
50
51 2
        $output->writeln('done');
52 2
    }
53
}
54