Completed
Push — 1.x ( 747b4c...b6bf38 )
by Adrian
04:52 queued 11s
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->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