DeleteAlias::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 DeleteAlias extends AbstractMigration
7
{
8
    /**
9
     * Get validation rules
10
     *
11
     * @return array
12
     */
13 4
    public function getValidationRules(): array
14
    {
15
        return [
16 4
            'index' => 'required|string',
17
            'name' => 'required|string'
18
        ];
19
    }
20
    
21
    /**
22
     * Pre check
23
     *
24
     * @param Client $esClient
25
     * @param array $params
26
     *
27
     * @throws \Exception
28
     */
29 3
    public function preCheck(Client $esClient, array $params)
30
    {
31 3
        $index = $params['index'];
32 3
        if (!$esClient->indices()->exists(['index' => $index])) {
33 1
            throw new \Exception(sprintf("Index not exist: %s", $index));
34
        }
35
    
36 2
        if (!$esClient->indices()->existsAlias($params)) {
37 1
            throw new \Exception(sprintf("Alias not exist: %s", $params['name']));
38
        };
39 1
    }
40
    
41
    /**
42
     * Start migration
43
     *
44
     * @param Client $esClient
45
     * @param array $params
46
     */
47 1
    public function startMigration(Client $esClient, array $params)
48
    {
49 1
        $esClient->indices()->deleteAlias($params);
50 1
    }
51
    
52
    /**
53
     * Post check
54
     *
55
     * @param Client $esClient
56
     * @param array $params
57
     *
58
     * @throws \Exception
59
     */
60 1
    public function postCheck(Client $esClient, array $params)
61
    {
62 1
        if ($esClient->indices()->existsAlias($params)) {
63
            throw new \Exception(sprintf("Alias exist: %s", $params['name']));
64
        };
65 1
    }
66
}
67