Completed
Pull Request — master (#108)
by
unknown
05:01 queued 02:24
created

SamplerAggregation::getShardSize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
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;
13
14
use ONGR\ElasticsearchDSL\Aggregation\Type\BucketingTrait;
15
16
class SamplerAggregation extends AbstractAggregation
17
{
18
    use BucketingTrait;
19
20
    /**
21
     * Defines how many results will be received from each shard
22
     * @param string $shardSize
23
     */
24
    private $shardSize;
25
26
    /**
27
     * Inner aggregations container init.
28
     *
29
     * @param string $name
30
     * @param string $field
31
     * @param int    $shardSize
32
     */
33
    public function __construct(
34
        $name,
35
        $field = null,
36
        $shardSize = null
37
    ) {
38
        parent::__construct($name);
39
40
        $this->setField($field);
41
        $this->setShardSize($shardSize);
42
    }
43
44
    /**
45
     * @return mixed
46
     */
47
    public function getShardSize()
48
    {
49
        return $this->shardSize;
50
    }
51
52
    /**
53
     * @param mixed $shardSize
54
     */
55
    public function setShardSize($shardSize)
56
    {
57
        $this->shardSize = $shardSize;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function getType()
64
    {
65
        return 'sampler';
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getArray()
72
    {
73
        $out = array_filter(
74
            [
75
                'field' => $this->getField(),
76
                'shard_size' => $this->getShardSize(),
77
            ],
78
            function ($val) {
79
                return $val;
80
            }
81
        );
82
        return $this->processArray($out);
83
    }
84
}
85