Completed
Pull Request — master (#111)
by
unknown
02:53
created

DateHistogramAggregation::getType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
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;
13
14
use ONGR\ElasticsearchDSL\Aggregation\Type\BucketingTrait;
15
16
/**
17
 * Class representing Histogram aggregation.
18
 *
19
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html
20
 */
21
class DateHistogramAggregation extends AbstractAggregation
22
{
23
    use BucketingTrait;
24
25
    /**
26
     * @var string
27
     */
28
    protected $interval;
29
30
    /**
31
     * Inner aggregations container init.
32
     *
33
     * @param string $name
34
     * @param string $field
35
     * @param string $interval
36
     */
37
    public function __construct(
38
        $name,
39
        $field = null,
40
        $interval = null
41
    ) {
42
        parent::__construct($name);
43
44
        $this->setField($field);
45
        $this->setInterval($interval);
46
    }
47
48
    /**
49
     * @return int
50
     */
51
    public function getInterval()
52
    {
53
        return $this->interval;
54
    }
55
56
    /**
57
     * @param string $interval
58
     */
59
    public function setInterval($interval)
60
    {
61
        $this->interval = $interval;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function getType()
68
    {
69
        return 'date_histogram';
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function getArray()
76
    {
77
        if (!$this->getField() || !$this->getInterval()) {
78
            throw new \LogicException('Date histogram aggregation must have field and interval set.');
79
        }
80
81
        $out = [
82
            'field' => $this->getField(),
83
            'interval' => $this->getInterval(),
84
        ];
85
        $out = $this->processArray($out);
86
87
        return $out;
88
    }
89
}
90