Reindex   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 11
dl 0
loc 57
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A startMigration() 0 3 1
A postCheck() 0 2 1
A preCheck() 0 9 2
A getValidationRules() 0 6 1
1
<?php
2
namespace Triadev\EsMigration\Business\Migration;
3
4
use Elasticsearch\Client;
5
6
class Reindex extends AbstractMigration
7
{
8
    /**
9
     * Get validation rules
10
     *
11
     * @return array
12
     */
13 3
    public function getValidationRules(): array
14
    {
15
        return [
16 3
            'body' => 'required|array',
17
            'body.source.index' => 'required|string',
18
            'body.dest.index' => 'required|string'
19
        ];
20
    }
21
    
22
    /**
23
     * Pre check
24
     *
25
     * @param Client $esClient
26
     * @param array $params
27
     *
28
     * @throws \Exception
29
     */
30 2
    public function preCheck(Client $esClient, array $params)
31
    {
32 2
        $indices = implode(',', [
33 2
            array_get($params, 'body.source.index'),
34 2
            array_get($params, 'body.dest.index')
35
        ]);
36
        
37 2
        if (!$esClient->indices()->exists(['index' => $indices])) {
38 1
            throw new \Exception(sprintf("Index not exist: %s", $indices));
39
        }
40 1
    }
41
    
42
    /**
43
     * Start migration
44
     *
45
     * @param Client $esClient
46
     * @param array $params
47
     */
48 1
    public function startMigration(Client $esClient, array $params)
49
    {
50 1
        $esClient->reindex($params);
51 1
    }
52
    
53
    /**
54
     * Post check
55
     *
56
     * @param Client $esClient
57
     * @param array $params
58
     *
59
     * @throws \Exception
60
     */
61 1
    public function postCheck(Client $esClient, array $params)
62
    {
63
        // TODO: Implement postCheck() method.
64 1
    }
65
}
66