Completed
Push — develop ( d50c7c...589236 )
by Quang
08:06
created

TermsAggregation   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMinDocCount() 0 3 1
A setMinDocCount() 0 5 1
A toArray() 0 13 2
1
<?php namespace Nord\Lumen\Elasticsearch\Search\Aggregation\Bucket;
2
3
use Nord\Lumen\Elasticsearch\Search\Traits\HasField;
4
5
/**
6
 * A multi-bucket value source based aggregation where buckets are dynamically built - one per unique value.
7
 *
8
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html
9
 */
10
class TermsAggregation extends AbstractAggregation
11
{
12
    use HasField;
13
14
    /**
15
     * @var int
16
     */
17
    protected $minDocCount;
18
19
    /**
20
     * @return int|null
21
     */
22
    public function getMinDocCount(): ?int
23
    {
24
        return $this->minDocCount;
25
    }
26
27
    /**
28
     * @param int $minDocCount
29
     */
30
    public function setMinDocCount(int $minDocCount)
31
    {
32
        $this->minDocCount = $minDocCount;
33
34
        return $this;
35
    }
36
37
    public function toArray()
38
    {
39
        $data = [
40
            'terms' => [
41
                'field' => $this->getField(),
42
            ],
43
        ];
44
45
        if (!empty($this->getMinDocCount())) {
46
            $data['terms']['min_doc_count'] = $this->getMinDocCount();
47
        }
48
49
        return $data;
50
    }
51
}
52