DeleteIndex   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 6
eloc 10
dl 0
loc 56
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A postCheck() 0 6 2
A startMigration() 0 3 1
A getValidationRules() 0 4 1
A preCheck() 0 6 2
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