DeleteIndex::startMigration()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
namespace Triadev\EsMigration\Business\Migration;
3
4
use Elasticsearch\Client;
5
6
class DeleteIndex extends AbstractMigration
7
{
8
    /**
9
     * Get validation rules
10
     *
11
     * @return array
12
     */
13 5
    public function getValidationRules(): array
14
    {
15
        return [
16 5
            'index' => 'required|string'
17
        ];
18
    }
19
    
20
    /**
21
     * Pre check
22
     *
23
     * @param Client $esClient
24
     * @param array $params
25
     *
26
     * @throws \Exception
27
     */
28 4
    public function preCheck(Client $esClient, array $params)
29
    {
30 4
        $index = $params['index'];
31
    
32 4
        if (!$esClient->indices()->exists(['index' => $params['index']])) {
33 1
            throw new \Exception(sprintf("Index not exist: %s", $index));
34
        }
35 3
    }
36
    
37
    /**
38
     * Start migration
39
     *
40
     * @param Client $esClient
41
     * @param array $params
42
     */
43 3
    public function startMigration(Client $esClient, array $params)
44
    {
45 3
        $esClient->indices()->delete($params);
46 3
    }
47
    
48
    /**
49
     * Post check
50
     *
51
     * @param Client $esClient
52
     * @param array $params
53
     *
54
     * @throws \Exception
55
     */
56 3
    public function postCheck(Client $esClient, array $params)
57
    {
58 3
        $index = $params['index'];
59
    
60 3
        if ($esClient->indices()->exists(['index' => $params['index']])) {
61
            throw new \Exception(sprintf("Index exist: %s", $index));
62
        }
63 3
    }
64
}
65