Completed
Push — master ( 103460...224772 )
by GBProd
02:10
created

PutIndexSettingsHandler::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 16
loc 16
ccs 9
cts 9
cp 1
rs 9.4285
cc 2
eloc 9
nc 2
nop 2
crap 2
1
<?php
2
3
namespace GBProd\ElasticaExtraBundle\Handler;
4
5
use Elastica\Client;
6
use GBProd\ElasticaExtraBundle\Repository\ClientRepository;
7
use GBProd\ElasticaExtraBundle\Repository\IndexConfigurationRepository;
8
9
/**
10
 * Handler to put index settings command
11
 *
12
 * @author gbprod <[email protected]>
13
 */
14 View Code Duplication
class PutIndexSettingsHandler
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...
15
{
16
    /**
17
     * @var IndexConfigurationRepository
18
     */
19
    private $configurationRepository;
20
21
    /**
22
     * @param IndexConfigurationRepository $configurationRepository
23
     */
24 3
    public function __construct(IndexConfigurationRepository $configurationRepository)
25
    {
26 3
        $this->configurationRepository = $configurationRepository;
27 3
    }
28
29
    /**
30
     * Handle index creation command
31
     *
32
     * @param Client $client
33
     * @param string $index
34
     */
35 2
    public function handle(Client $client, $index)
36
    {
37 2
        $settings = $this
38
            ->configurationRepository
39 2
            ->getSettings($index)
40 2
        ;
41
42 2
        if (null === $settings) {
43 1
            throw new \InvalidArgumentException();
44
        }
45
46
        $client
47 1
            ->getIndex($index)
48 1
            ->setSettings($settings)
49
        ;
50 1
    }
51
52
}
53