UpdateIndexSetting::getValidationRules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
namespace Triadev\EsMigration\Business\Migration;
3
4
use Elasticsearch\Client;
5
6
class UpdateIndexSetting 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
            'body' => 'required|array'
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 2
    }
36
    
37
    /**
38
     * Start migration
39
     *
40
     * @param Client $esClient
41
     * @param array $params
42
     */
43 2
    public function startMigration(Client $esClient, array $params)
44
    {
45 2
        $esClient->indices()->putSettings($params);
46 1
    }
47
    
48
    /**
49
     * Post check
50
     *
51
     * @param Client $esClient
52
     * @param array $params
53
     *
54
     * @throws \Exception
55
     */
56 1
    public function postCheck(Client $esClient, array $params)
57
    {
58
        // TODO: Implement postCheck() method.
59 1
    }
60
}
61