Completed
Pull Request — master (#148)
by Simonas
02:51
created

ChildrenAggregation   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 60
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getChildren() 0 4 1
A __construct() 0 6 1
A setChildren() 0 4 1
A getType() 0 4 1
A getArray() 0 8 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