Completed
Push — master ( a7a684...a86091 )
by GBProd
02:32
created

PutIndexSettingsHandler::extractSettings()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2.1481

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 2
cts 3
cp 0.6667
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2.1481
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 settings command
10
 *
11
 * @author gbprod <[email protected]>
12
 */
13
class PutIndexSettingsHandler
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
            ->putSettings([
55 1
                'index' => $indexId,
56
                'body'  => [
57 1
                    'settings' => $this->extractSettings($config),
58 1
                ],
59 1
            ])
60
        ;
61 1
    }
62
    
63
    private function extractSettings($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...
64
    {
65 1
        if (isset($config['settings'])) {
66 1
            return $config['settings'];
67
        }
68
        
69
        return [];
70
    }
71
}