Completed
Push — master ( a86091...f009d3 )
by GBProd
02:31
created

PutIndexMappingsHandler   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 94.12%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 4
dl 57
loc 57
ccs 16
cts 17
cp 0.9412
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A handle() 17 17 3
A extractMapping() 8 8 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 GBProd\ElasticsearchExtraBundle\Repository\ClientRepository;
6
use GBProd\ElasticsearchExtraBundle\Repository\IndexConfigurationRepository;
7
8
/**
9
 * Handler to put index mappings command
10
 *
11
 * @author gbprod <[email protected]>
12
 */
13 View Code Duplication
class PutIndexMappingsHandler
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 ClientRepository
17
     */
18
    private $clientRepository;
19
20
    /**
21
     * @var IndexConfigurationRepository
22
     */
23
    private $configurationRepository;
24
25
    /**
26
     * @param ClientRepository             $clientRepository
27
     * @param IndexConfigurationRepository $configurationRepository
28
     */
29
    public function __construct(
30
        ClientRepository $clientRepository,
31
        IndexConfigurationRepository $configurationRepository
32
    ) {
33 1
        $this->clientRepository        = $clientRepository;
34 1
        $this->configurationRepository = $configurationRepository;
35 1
    }
36
37
    /**
38
     * Handle index creation command
39
     *
40
     * @param string $clientId
41
     * @param string $indexId
42
     */
43 1
    public function handle($clientId, $indexId)
44
    {
45 1
        $client = $this->clientRepository->get($clientId);
46 1
        $config = $this->configurationRepository->get($clientId, $indexId);
47
48 1
        if (null === $client || null === $config) {
49 1
            throw new \InvalidArgumentException();
50
        }
51
52
        $client
53 1
            ->indices()
54 1
            ->putMapping([
55 1
                'index' => $indexId,
56 1
                'body'  => $this->extractMapping($config),
57 1
            ])
58
        ;
59 1
    }
60
    
61
    private function extractMapping($config)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
62
    {
63 1
        if (isset($config['mappings'])) {
64 1
            return $config['mappings'];
65
        }
66
        
67
        return [];
68
    }
69
}