Passed
Pull Request — develop (#108)
by Quang
02:00
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
13
    use HasField;
14
15
    /**
16
     * @var int
17
     */
18
    protected $minDocCount;
19
20
    /**
21
     * @return int|null
22
     */
23
    public function getMinDocCount(): ?int
24
    {
25
        return $this->minDocCount;
26
    }
27
28
    /**
29
     * @param int $minDocCount
30
     */
31
    public function setMinDocCount(int $minDocCount)
32
    {
33
        $this->minDocCount = $minDocCount;
34
35
        return $this;
36
    }
37
38
    public function toArray()
39
    {
40
        $data = [
41
            'terms' => [
42
                'field' => $this->getField(),
43
            ],
44
        ];
45
46
        if (!empty($this->getMinDocCount())) {
47
            $data['terms']['min_doc_count'] = $this->getMinDocCount();
48
        }
49
50
        return $data;
51
    }
52
}
53