Passed
Push — master ( 0fcf63...232f8b )
by Adrian
02:24
created

Import::setBody()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 9
c 1
b 0
f 1
nc 3
nop 1
dl 0
loc 15
rs 9.9666
1
<?php
2
3
4
namespace Manticoresearch\Endpoints\Indices;
5
6
use Manticoresearch\Endpoints\EmulateBySql;
7
use Manticoresearch\Exceptions\RuntimeException;
8
9
class Import extends EmulateBySql
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $_index;
15
16
    public function setBody($params = null)
17
    {
18
        if (isset($this->_index)) {
19
            if (isset($params['path'])) {
20
                return parent::setBody([
21
                    'query' => 'IMPORT TABLE ' .
22
                        $this->_index .
23
                        ' FROM ' .
24
                        $params['path']
25
                ]);
26
27
            }
28
            throw new RuntimeException('Missing import index path in /indices/import');
29
        }
30
        throw new RuntimeException('Missing index name in /indices/import');
31
    }
32
33
    /**
34
     * @return mixed
35
     */
36
    public function getIndex()
37
    {
38
        return $this->_index;
39
    }
40
41
    /**
42
     * @param mixed $index
43
     */
44
    public function setIndex($index)
45
    {
46
        $this->_index = $index;
47
    }
48
}