Completed
Push — 1.x ( 747b4c...b6bf38 )
by Adrian
04:52 queued 11s
created

Query   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 3 1
A add() 0 3 1
A convertArray() 0 18 5
1
<?php
2
3
4
namespace Manticoresearch;
5
6
class Query implements Arrayable
7
{
8
    protected $params = [];
9
10
    public function add($k, $v)
11
    {
12
        $this->params[$k] = $v;
13
    }
14
    public function toArray()
15
    {
16
        return  $this->convertArray($this->params);
17
    }
18
19
    protected function convertArray($params)
20
    {
21
22
        $return = [];
23
        foreach ($params as $k => $v) {
24
            if ($v instanceof Arrayable) {
25
                $return[$k] = $v->toArray();
26
            } elseif (is_array($v)) {
27
                $return[$k] = $this->convertArray($v);
28
            } else {
29
                if ($v!==null) {
30
                    $return[$k] = $v;
31
                } else {
32
                    return null;
33
                }
34
            }
35
        }
36
        return $return;
37
    }
38
}
39