Completed
Pull Request — master (#348)
by
unknown
09:42 queued 08:20
created

TermsAggregation   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 43
c 0
b 0
f 0
rs 10
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
27
    use ScriptAwareTrait;
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 = null,
32
        ?string $script = null
33
    ) {
34
        parent::__construct($name);
35
36
        $this->setField($field);
37
        $this->setScript($script);
38
    }
39
40
    public function getType(): string
41
    {
42
        return 'terms';
43
    }
44
45
    public function getArray(): array
46
    {
47
        return array_filter(
48
            [
49
                'field' => $this->getField(),
50
                'script' => $this->getScript(),
51
            ]
52
        );
53
    }
54
}
55