Completed
Push — master ( 9552d6...4b2b1b )
by Simonas
08:12
created

AdjacencyMatrixAggregation::addFilter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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\ElasticsearchDSL\Aggregation\Bucketing;
13
14
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
15
use ONGR\ElasticsearchDSL\Aggregation\Type\BucketingTrait;
16
use ONGR\ElasticsearchDSL\BuilderInterface;
17
18
/**
19
 * Class representing adjacency matrix aggregation.
20
 *
21
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-adjacency-matrix-aggregation.html
22
 */
23
class AdjacencyMatrixAggregation extends AbstractAggregation
24
{
25
    const FILTERS = 'filters';
26
27
    use BucketingTrait;
28
29
    /**
30
     * @var BuilderInterface[]
31
     */
32
    private $filters = [
33
        self::FILTERS => []
34
    ];
35
36
    /**
37
     * Inner aggregations container init.
38
     *
39
     * @param string             $name
40
     * @param BuilderInterface[] $filters
41
     */
42
    public function __construct($name, $filters = [])
43
    {
44
        parent::__construct($name);
45
46
        foreach ($filters as $name => $filter) {
47
            $this->addFilter($name, $filter);
48
        }
49
    }
50
51
    /**
52
     * @param string           $name
53
     * @param BuilderInterface $filter
54
     *
55
     * @throws \LogicException
56
     *
57
     * @return self
58
     */
59
    public function addFilter($name, BuilderInterface $filter)
60
    {
61
        $this->filters[self::FILTERS][$name] = $filter->toArray();
62
63
        return $this;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function getArray()
70
    {
71
        return $this->filters;
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function getType()
78
    {
79
        return 'adjacency_matrix';
80
    }
81
}
82