UpdateByQuery   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 5
eloc 7
dl 0
loc 51
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getValidationRules() 0 4 1
A startMigration() 0 3 1
A postCheck() 0 2 1
A preCheck() 0 5 2
1
<?php
2
namespace Triadev\EsMigration\Business\Migration;
3
4
use Elasticsearch\Client;
5
6
class UpdateByQuery extends AbstractMigration
7
{
8
    /**
9
     * Get validation rules
10
     *
11
     * @return array
12
     */
13 2
    public function getValidationRules(): array
14
    {
15
        return [
16 2
            '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 1
    public function preCheck(Client $esClient, array $params)
29
    {
30 1
        $index = $params['index'];
31 1
        if (!$esClient->indices()->exists(['index' => $index])) {
32
            throw new \Exception(sprintf("Index not exist: %s", $index));
33
        }
34 1
    }
35
    
36
    /**
37
     * Start migration
38
     *
39
     * @param Client $esClient
40
     * @param array $params
41
     */
42 1
    public function startMigration(Client $esClient, array $params)
43
    {
44 1
        $esClient->updateByQuery($params);
45 1
    }
46
    
47
    /**
48
     * Post check
49
     *
50
     * @param Client $esClient
51
     * @param array $params
52
     *
53
     * @throws \Exception
54
     */
55 1
    public function postCheck(Client $esClient, array $params)
56
    {
57
        // TODO: Implement postCheck() method.
58 1
    }
59
}
60