Join   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 17
c 2
b 0
f 1
dl 0
loc 41
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCLuster() 0 3 1
A setCluster() 0 3 1
A setBody() 0 18 6
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