Passed
Push — 1.x ( 77e7f6...966118 )
by Adrian
02:40 queued 12s
created

Query::_toArray()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 17
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 17
rs 9.5555
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->_toArray($this->_params);
17
    }
18
19
    protected function _toArray($params)
20
    {
21
        $return = [];
22
        foreach ($params as $k => $v) {
23
            if ($v instanceof Arrayable) {
24
                $return[$k] = $v->toArray();
25
            } elseif (is_array($v)) {
26
                $return[$k] = $this->_toArray($v);
27
            } else {
28
                if ($v!==null) {
29
                    $return[$k] = $v;
30
                } else {
31
                    return null;
32
                }
33
            }
34
        }
35
        return $return;
36
    }
37
}
38