Completed
Push — legacy ( c3f933 )
by Simonas
95:41
created

NotFilter::setFilter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\ElasticsearchBundle\DSL\Filter;
13
14
use ONGR\ElasticsearchBundle\DSL\BuilderInterface;
15
use ONGR\ElasticsearchBundle\DSL\ParametersTrait;
16
17
/**
18
 * Represents Elasticsearch "not" filter.
19
 *
20
 * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-not-filter.html
21
 */
22
class NotFilter implements BuilderInterface
23
{
24
    use ParametersTrait;
25
26
    /**
27
     * @var BuilderInterface
28
     */
29
    private $filter;
30
31
    /**
32
     * @param BuilderInterface $filter     Filter.
33
     * @param array            $parameters Optional parameters.
34
     */
35
    public function __construct(BuilderInterface $filter = null, array $parameters = [])
36
    {
37
        if ($filter !== null) {
38
            $this->setFilter($filter);
39
        }
40
        $this->setParameters($parameters);
41
    }
42
    
43
    /**
44
     * Returns filter.
45
     *
46
     * @return BuilderInterface
47
     */
48
    public function getFilter()
49
    {
50
        return $this->filter;
51
    }
52
53
    /**
54
     * Sets filter.
55
     *
56
     * @param BuilderInterface $filter
57
     */
58
    public function setFilter(BuilderInterface $filter)
59
    {
60
        $this->filter = $filter;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function getType()
67
    {
68
        return 'not';
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function toArray()
75
    {
76
        $query = [];
77
        $query['filter'] = [$this->filter->getType() => $this->filter->toArray()];
78
79
        $output = $this->processArray($query);
80
81
        return $output;
82
    }
83
}
84