PutIndexMappingsHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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