ChildrenAggregation   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getChildren() 0 4 1
A __construct() 0 6 1
A setChildren() 0 6 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
     * @param string $children
54
     *
55
     * @return $this
56
     */
57
    public function setChildren($children)
58
    {
59
        $this->children = $children;
60
61
        return $this;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function getType()
68
    {
69
        return 'children';
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function getArray()
76
    {
77
        if (count($this->getAggregations()) == 0) {
78
            throw new \LogicException("Children aggregation `{$this->getName()}` has no aggregations added");
79
        }
80
81
        return ['type' => $this->getChildren()];
82
    }
83
}
84