Completed
Pull Request — master (#348)
by
unknown
01:15
created

AutoDateHistogramAggregation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 49
rs 10
c 0
b 0
f 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
declare(strict_types=1);
13
14
namespace ONGR\ElasticsearchDSL\Aggregation\Bucketing;
15
16
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
17
use ONGR\ElasticsearchDSL\Aggregation\Type\BucketingTrait;
18
use ONGR\ElasticsearchDSL\BuilderInterface;
19
20
/**
21
 * Class representing AutoDateHistogramAggregation.
22
 *
23
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-autodatehistogram-aggregation.html
24
 */
25
class AutoDateHistogramAggregation extends AbstractAggregation
26
{
27
    use BucketingTrait;
28
29
    public function __construct(
30
        private string $name,
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_PRIVATE, expecting T_VARIABLE
Loading history...
31
        private string $field,
32
        private ?int $buckets = null,
33
        private ?string $format = null
34
    ) {
35
        parent::__construct($name);
36
37
        $this->setField($field);
38
39
        if ($buckets) {
40
            $this->addParameter('buckets', $buckets);
41
        }
42
43
        if ($format) {
44
            $this->addParameter('format', $format);
45
        }
46
    }
47
48
    public function getArray(): array
49
    {
50
        return array_filter(
51
            [
52
                'field' => $this->getField(),
53
            ]
54
        );
55
    }
56
57
    public function getType(): string
58
    {
59
        return 'auto_date_histogram';
60
    }
61
}
62