BoolQuery::_addFilter()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.2248
c 0
b 0
f 0
cc 5
nc 3
nop 2
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
}