Completed
Pull Request — master (#148)
by Simonas
05:22
created

ChildrenAggregation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
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
17
/**
18
 * Class representing ChildrenAggregation.
19
 *
20
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-children-aggregation.html
21
 */
22
class ChildrenAggregation extends AbstractAggregation
23
{
24
    use BucketingTrait;
25
26
    /**
27
     * @var string
28
     */
29
    private $children;
30
31
    /**
32
     * Return children.
33
     *
34
     * @return string
35
     */
36
    public function getChildren()
37
    {
38
        return $this->children;
39
    }
40
41
    /**
42
     * @param string $name
43
     * @param string $children
44
     */
45
    public function __construct($name, $children = null)
46
    {
47
        parent::__construct($name);
48
49
        $this->setChildren($children);
50
    }
51
52
    /**
53
     * Sets children.
54
     *
55
     * @param string $children
56
     */
57
    public function setChildren($children)
58
    {
59
        $this->children = $children;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function getType()
66
    {
67
        return 'children';
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function getArray()
74
    {
75
        if (count($this->getAggregations()) == 0) {
76
            throw new \LogicException("Children aggregation `{$this->getName()}` has no aggregations added");
77
        }
78
79
        return ['type' => $this->getChildren()];
80
    }
81
}
82