Completed
Push — master ( ec539d...346131 )
by Adrian
02:33 queued 11s
created

Query::_toArray()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 12
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 18
rs 9.5555
1
<?php
2
3
4
namespace Manticoresearch;
5
6
7
class Query implements Arrayable
8
{
9
    protected $_params;
10
11
    public function add($k,$v) {
12
        $this->_params[$k] = $v;
13
    }
14
    public function toArray()
15
    {
16
17
       return  $this->_toArray($this->_params);
18
    }
19
20
    protected function _toArray($params)
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->_toArray($v);
28
            } else {
29
                if($v!==null) {
30
                    $return[$k] = $v;
31
                }else {
32
                    return null;
33
                }
34
35
            }
36
        }
37
        return $return;
38
    }
39
}
40