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

Query   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 3 1
A _toArray() 0 17 5
A add() 0 3 1
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