Alter::setBody()   B
last analyzed

Complexity

Conditions 8
Paths 8

Size

Total Lines 28
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 8
eloc 21
c 2
b 0
f 1
nc 8
nop 1
dl 0
loc 28
rs 8.4444
1
<?php
2
3
namespace Manticoresearch\Endpoints\Cluster;
4
5
use Manticoresearch\Endpoints\EmulateBySql;
6
use Manticoresearch\Endpoints\Sql;
7
use Manticoresearch\Exceptions\RuntimeException;
8
use Manticoresearch\Utils;
9
10
class Alter extends EmulateBySql
11
{
12
    use Utils;
13
    /**
14
     * @var string
15
     */
16
    protected $cluster;
17
18
    public function setBody($params = null)
19
    {
20
        if (isset($this->cluster)) {
21
            if (isset($params['operation'])) {
22
                switch ($params['operation']) {
23
                    case 'add':
24
                        if (isset($params['index'])) {
25
                            return parent::setBody(['query' => "ALTER CLUSTER " .
26
                                $this->cluster . " ADD  " . $params['index']]);
27
                        }
28
                        throw new RuntimeException('Index name is missing.');
29
                        break;
30
                    case 'drop':
31
                        if (isset($params['index'])) {
32
                            return parent::setBody(['query' => "ALTER CLUSTER " .
33
                                $this->cluster . " DROP  " . $params['index']]);
34
                        }
35
                        throw new RuntimeException('Index name is missing.');
36
                        break;
37
                    case 'update':
38
                        return parent::setBody(['query' => "ALTER CLUSTER " .$this->cluster . " UPDATE nodes"]);
39
                        break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
40
                }
41
                throw new RuntimeException('Unknown cluster operation');
42
            }
43
            throw new RuntimeException('Cluster operation is missing');
44
        }
45
        throw new RuntimeException('Cluster name is missing.');
46
    }
47
48
    /**
49
     * @return mixed
50
     */
51
    public function getCLuster()
52
    {
53
        return $this->cluster;
54
    }
55
56
    /**
57
     * @param mixed $cluster
58
     */
59
    public function setCluster($cluster)
60
    {
61
        $this->cluster = $cluster;
62
    }
63
}
64