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

TermsAggregation::getMinDocCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
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