PutIndexSettingsHandler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 52
ccs 14
cts 16
cp 0.875
rs 10
c 1
b 1
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 18 3
A extractSettings() 0 8 2
1
<?php
2
3
namespace GBProd\ElasticsearchExtraBundle\Handler;
4
5
use Elasticsearch\Client;
6
use GBProd\ElasticsearchExtraBundle\Repository\ClientRepository;
7
use GBProd\ElasticsearchExtraBundle\Repository\IndexConfigurationRepository;
8
9
/**
10
 * Handler to put index settings command
11
 *
12
 * @author gbprod <[email protected]>
13
 */
14
class PutIndexSettingsHandler
15
{
16
    /**
17
     * @var IndexConfigurationRepository
18
     */
19
    private $configurationRepository;
20
21
    /**
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, $index)
36
    {
37 1
        $config = $this->configurationRepository->get($index);
38
39 1
        if (null === $client || null === $config) {
40
            throw new \InvalidArgumentException();
41
        }
42
43 1
        $client
44 1
            ->indices()
45 1
            ->putSettings([
46 1
                'index' => $index,
47
                'body'  => [
48 1
                    'settings' => $this->extractSettings($config),
49 1
                ],
50 1
            ])
51
        ;
52 1
    }
53
    
54
    /**
55
     * @return array
56
     */
57
    private function extractSettings($config)
58
    {
59 1
        if (isset($config['settings'])) {
60 1
            return $config['settings'];
61
        }
62
63
        return [];
64
    }
65
}
66