Completed
Pull Request — master (#348)
by
unknown
09:42 queued 08:20
created

ChildrenAggregation   A

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
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
declare(strict_types=1);
13
14
namespace ONGR\ElasticsearchDSL\Aggregation\Bucketing;
15
16
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
17
use ONGR\ElasticsearchDSL\Aggregation\Type\BucketingTrait;
18
19
/**
20
 * Class representing ChildrenAggregation.
21
 *
22
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-children-aggregation.html
23
 */
24
class ChildrenAggregation extends AbstractAggregation
25
{
26
    use BucketingTrait;
27
28
    public function __construct(private string $name, private ?string $children = null)
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_PRIVATE, expecting T_VARIABLE
Loading history...
29
    {
30
        parent::__construct($name);
31
    }
32
33
    public function getChildren(): ?string
34
    {
35
        return $this->children;
36
    }
37
38
    public function setChildren(?string $children): static
39
    {
40
        $this->children = $children;
41
42
        return $this;
43
    }
44
45
    public function getType(): string
46
    {
47
        return 'children';
48
    }
49
50
    public function getArray(): array
51
    {
52
        if (count($this->getAggregations()) == 0) {
53
            throw new \LogicException("Children aggregation `{$this->getName()}` has no aggregations added");
54
        }
55
56
        return ['type' => $this->getChildren()];
57
    }
58
}
59