Completed
Push — master ( d72a06...ba0ad0 )
by GBProd
04:38
created

DeleteIndexHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 90%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 1
cbo 3
dl 37
loc 37
ccs 9
cts 10
cp 0.9
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A handle() 15 15 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
namespace GBProd\ElasticsearchExtraBundle\Handler;
4
5
use Elasticsearch\Client;
6
use GBProd\ElasticsearchExtraBundle\Repository\IndexConfigurationRepository;
7
8
/**
9
 * Handler to delete index command
10
 *
11
 * @author gbprod <[email protected]>
12
 */
13 View Code Duplication
class DeleteIndexHandler
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
    /**
16
     * @var IndexConfigurationRepository
17
     */
18
    private $configurationRepository;
19
20
    /**
21
     * @param IndexConfigurationRepository $configurationRepository
22
     */
23
    public function __construct(IndexConfigurationRepository $configurationRepository)
24
    {
25 1
        $this->configurationRepository = $configurationRepository;
26 1
    }
27
28
    /**
29
     * Handle index deletion command
30
     *
31
     * @param Client $client
32
     * @param string $index
33
     */
34
    public function handle(Client $client, $index)
35
    {
36 1
        $config = $this->configurationRepository->get($index);
37
38 1
        if (null === $config) {
39
            throw new \InvalidArgumentException();
40
        }
41
42
        $client
43 1
            ->indices()
44 1
            ->delete([
45 1
                'index' => $index,
46 1
            ])
47
        ;
48 1
    }
49
}
50