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

PutIndexMappingsHandler::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2.0023

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 19
ccs 11
cts 12
cp 0.9167
rs 9.4285
cc 2
eloc 11
nc 2
nop 3
crap 2.0023
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