BoolQuery   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A _addFilter() 0 24 5
1
<?php
2
/**
3
 *
4
 * @author Mihkel Viilveer <[email protected]>
5
 * @date 14.11.2014
6
 */
7
8
namespace opus\elastic\elastica\filter;
9
10
use Elastica\Exception\InvalidException;
11
use Elastica\Filter\AbstractFilter;
12
13
/**
14
 * Class Bool
15
 *
16
 * @author Mihkel Viilveer <[email protected]>
17
 * @package opus\elastic\elastica\filter
18
 */
19
class BoolQuery extends \Elastica\Query\BoolQuery
20
{
21
    /**
22
     * Adds general filter based on type
23
     *
24
     * @param  string                               $type Filter type
25
     * @param  array|\Elastica\Filter\AbstractFilter $args Filter data
26
     * @throws \Elastica\Exception\InvalidException
27
     * @return \Elastica\Filter\Bool           Current object
28
     */
29
    protected function _addFilter($type, $args)
30
    {
31
        if ($args instanceof AbstractFilter) {
32
            $args = $args->toArray();
33
        }
34
        else if (!is_array($args)) {
35
            throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Filter');
36
        }
37
        else{
38
            $parsedArgs = array();
39
            foreach($args as $filter){
40
                if($filter instanceof AbstractFilter){
41
                    $parsedArgs[] = $filter->toArray();
42
                } else {
43
                    $parsedArgs[] = $filter;
44
                }
45
            }
46
            $args = $parsedArgs;
47
        }
48
49
        $varName = '_' . $type;
50
        $this->{$varName}[] = $args;
51
        return $this;
52
    }
53
}