IndexDropCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 54.55 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 24
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 14 1
A execute() 24 24 2

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
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\ElasticsearchBundle\Command;
13
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Input\InputOption;
16
use Symfony\Component\Console\Output\OutputInterface;
17
use Symfony\Component\Console\Style\SymfonyStyle;
18
19
class IndexDropCommand extends AbstractIndexServiceAwareCommand
20
{
21
    const NAME = 'ongr:es:index:drop';
22
23
    protected function configure()
24
    {
25
        parent::configure();
26
27
        $this
28
            ->setName(self::NAME)
29
            ->setDescription('Drops ElasticSearch index.')
30
            ->addOption(
31
                'force',
32
                'f',
33
                InputOption::VALUE_NONE,
34
                'Force option is mandatory to drop the index.'
35
            );
36
    }
37
38 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...
39
    {
40
        $io = new SymfonyStyle($input, $output);
41
        if ($input->getOption('force')) {
42
            $index = $this->getIndex($input->getOption(parent::INDEX_OPTION));
43
44
            $client =
0 ignored issues
show
Unused Code introduced by
$client is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
45
46
            $result = $index->dropIndex();
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
47
48
            $io->text(
49
                sprintf(
50
                    'The index <comment>`%s`</comment> was successfully dropped.',
51
                    $index->getIndexName()
52
                )
53
            );
54
        } else {
55
            $io->error('WARNING:');
56
            $io->text('This action should not be used in the production environment.');
57
            $io->error('Option --force is mandatory to drop the index.');
58
        }
59
60
        return 0;
61
    }
62
}
63