Alter   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 15
c 2
b 0
f 1
dl 0
loc 41
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getIndex() 0 3 1
A setBody() 0 17 6
A setIndex() 0 3 1
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