Completed
Push — master ( 4ef090...a7a684 )
by GBProd
02:22
created

DeleteIndexHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 7
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
crap 1
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 delete index command
10
 *
11
 * @author gbprod <[email protected]>
12
 */
13 View Code Duplication
class DeleteIndexHandler
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 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 deletion 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
            ->delete([
55 1
                'index' => $indexId,
56 1
            ])
57
        ;
58
    }
59
}