Completed
Push — master ( a36c27...010ee5 )
by GBProd
02:47
created

CreateIndexHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 48
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A handle() 0 17 3
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 for create index command
10
 *
11
 * @author gbprod <[email protected]>
12
 */
13
class CreateIndexHandler
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
            ->create([
55 1
                'index' => $indexId,
56 1
                'body'  => $config,
57 1
            ])
58
        ;
59
    }
60
}