Alter::setIndex()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 2
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
4
namespace Manticoresearch\Endpoints\Indices;
5
6
use Manticoresearch\Endpoints\EmulateBySql;
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 $index;
17
18
    public function setBody($params = null)
19
    {
20
        if (isset($this->index)) {
21
            if (isset($params['operation'])) {
22
                if ($params['operation'] === 'add' && isset($params['column'])) {
23
                        return parent::setBody(['query' => "ALTER TABLE " . $this->index . " ADD COLUMN " .
24
                            $params['column']['name'] . " " . strtoupper($params['column']['type'])]);
25
                }
26
                if ($params['operation'] === 'drop') {
27
                    return parent::setBody(['query' => "ALTER TABLE " . $this->index . " DROP COLUMN " .
28
                        $params['column']['name']]);
29
                }
30
                //@todo alter setting, once is merged in master
31
            }
32
            throw new RuntimeException('Operation is missing.');
33
        }
34
        throw new RuntimeException('Index name is missing.');
35
    }
36
37
    /**
38
     * @return mixed
39
     */
40
    public function getIndex()
41
    {
42
        return $this->index;
43
    }
44
45
    /**
46
     * @param mixed $index
47
     */
48
    public function setIndex($index)
49
    {
50
        $this->index = $index;
51
    }
52
}
53