Join::setCluster()   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
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 Join 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
            if (isset($params['node'])) {
27
                return parent::setBody(['query' => "JOIN CLUSTER ".$this->cluster." AT '".$params['node']."'"]);
28
            } else {
29
                $options =[];
30
                if (isset($params['path'])) {
31
                    $options[] = "'".$params['path']. "' AS path";
32
                }
33
                if (isset($params['nodes'])) {
34
                    $options[] = "'".$params['nodes']. "' AS nodes";
35
                }
36
                return parent::setBody(['query' => "JOIN CLUSTER ".$this->cluster.
37
                    ((count($options)>0)?" ".implode(',', $options):"")]);
38
            }
39
        }
40
        throw new RuntimeException('Cluster name is missing.');
41
    }
42
    /**
43
     * @return mixed
44
     */
45
    public function getCLuster()
46
    {
47
        return $this->cluster;
48
    }
49
50
    /**
51
     * @param mixed $cluster
52
     */
53
    public function setCluster($cluster)
54
    {
55
        $this->cluster = $cluster;
56
    }
57
}
58