AutoDateHistogramAggregation::getType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
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\BuilderInterface;
17
18
/**
19
 * Class representing AutoDateHistogramAggregation.
20
 *
21
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-autodatehistogram-aggregation.html
22
 */
23
class AutoDateHistogramAggregation extends AbstractAggregation
24
{
25
    use BucketingTrait;
26
27
    /**
28
     * Inner aggregations container init.
29
     *
30
     * @param string $name
31
     * @param string $field
32
     * @param int    $buckets
33
     * @param string $format
34
     */
35
    public function __construct($name, $field, $buckets = null, $format = null)
36
    {
37
        parent::__construct($name);
38
39
        $this->setField($field);
40
41
        if ($buckets) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $buckets of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
42
            $this->addParameter('buckets', $buckets);
43
        }
44
45
        if ($format) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $format of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
46
            $this->addParameter('format', $format);
47
        }
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getArray()
54
    {
55
        $data = array_filter(
56
            [
57
                'field' => $this->getField(),
58
            ]
59
        );
60
61
        return $data;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function getType()
68
    {
69
        return 'auto_date_histogram';
70
    }
71
}
72