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

CreateIndexHandler::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 2.0054

Importance

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