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

PutIndexMappingsHandler   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 94.74%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 7
c 3
b 1
f 1
lcom 1
cbo 3
dl 0
loc 51
ccs 18
cts 19
cp 0.9474
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 19 2
A isInvalid() 0 8 4
1
<?php
2
3
namespace GBProd\ElasticsearchExtraBundle\Handler;
4
5
use Elasticsearch\Client;
6
use GBProd\ElasticsearchExtraBundle\Repository\IndexConfigurationRepository;
7
8
/**
9
 * Handler to put index mappings command
10
 *
11
 * @author gbprod <[email protected]>
12
 */
13
class PutIndexMappingsHandler
14
{
15
    /**
16
     * @var IndexConfigurationRepository
17
     */
18
    private $configurationRepository;
19
20
    /**
21
     * @param ClientRepository             $clientRepository
0 ignored issues
show
Bug introduced by
There is no parameter named $clientRepository. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
22
     * @param IndexConfigurationRepository $configurationRepository
23
     */
24
    public function __construct(IndexConfigurationRepository $configurationRepository)
25
    {
26 1
        $this->configurationRepository = $configurationRepository;
27 1
    }
28
29
    /**
30
     * Handle index creation command
31
     *
32
     * @param Client $client
33
     * @param string $index
34
     */
35
    public function handle(Client $client, $index, $type)
36
    {
37 1
        $config = $this->configurationRepository->get($index);
38
39 1
        if ($this->isInvalid($config, $type)) {
40
            throw new \InvalidArgumentException();
41
        }
42
43 1
        $client
44 1
            ->indices()
45 1
            ->putMapping([
46 1
                'index' => $index,
47 1
                'type'  => $type,
48
                'body'  => [
49 1
                    $type => $config['mappings'][$type],
50 1
                ],
51 1
            ])
52
        ;
53 1
    }
54
55
    private function isInvalid($config, $type)
56
    {
57 1
        return null === $config
58 1
            || empty($type)
59 1
            || !isset($config['mappings'])
60 1
            || !isset($config['mappings'][$type])
61 1
        ;
62
    }
63
}
64