Create::setBody()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 5
eloc 9
c 2
b 0
f 1
nc 5
nop 1
dl 0
loc 14
rs 9.6111
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
/**
11
 * @todo maybe pattern should be a query parameter rather than body?
12
 * Class Status
13
 * @package Manticoresearch\Endpoints\Indices
14
 */
15
class Create extends EmulateBySql
16
{
17
    use Utils;
18
    /**
19
     * @var string
20
     */
21
    protected $cluster;
22
23
    public function setBody($params = null)
24
    {
25
        if (isset($this->cluster)) {
26
            $options = [];
27
            if (isset($params['path'])) {
28
                $options[] = "'" . $params['path'] . "' AS path";
29
            }
30
            if (isset($params['nodes'])) {
31
                $options[] = "'" . $params['nodes'] . "' AS nodes";
32
            }
33
            return parent::setBody(['query' => "CREATE CLUSTER " . $this->cluster .
34
                ((count($options) > 0) ? ' ' . implode(',', $options) : '')]);
35
        }
36
        throw new RuntimeException('Cluster name is missing.');
37
    }
38
39
    /**
40
     * @return mixed
41
     */
42
    public function getCLuster()
43
    {
44
        return $this->cluster;
45
    }
46
47
    /**
48
     * @param mixed $cluster
49
     */
50
    public function setCluster($cluster)
51
    {
52
        $this->cluster = $cluster;
53
    }
54
}
55