Completed
Push — master ( 72c2fc...074e1b )
by Simonas
04:21
created

TermsAggregation::getType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
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\ScriptAwareTrait;
17
18
/**
19
 * Class representing TermsAggregation.
20
 *
21
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html
22
 */
23
class TermsAggregation extends AbstractAggregation
24
{
25
    use BucketingTrait;
26
    use ScriptAwareTrait;
27
28
    /**
29
     * Inner aggregations container init.
30
     *
31
     * @param string $name
32
     * @param string $field
33
     * @param string $script
34
     */
35
    public function __construct($name, $field = null, $script = null)
36
    {
37
        parent::__construct($name);
38
39
        $this->setField($field);
40
        $this->setScript($script);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getType()
47
    {
48
        return 'terms';
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function getArray()
55
    {
56
        $data = array_filter(
57
            [
58
                'field' => $this->getField(),
59
                'script' => $this->getScript(),
60
            ]
61
        );
62
63
        return $data;
64
    }
65
}
66