Completed
Branch master (59afb3)
by Adam
05:44
created

GlobalAggregationTrait::wrapGlobal()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 1
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Coyote\Services\Elasticsearch\Aggs\Job;
4
5
trait GlobalAggregationTrait
6
{
7
    /**
8
     * @param array $body
9
     * @return array
10
     */
11
    protected function wrapGlobal(array $body): array
12
    {
13
        $nested = $body['aggs'][$this->name];
0 ignored issues
show
Bug introduced by
The property name does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
14
15
        if (!isset($body['aggs']['global'])) {
16
            $body['aggs']['global'] = [];
17
        }
18
19
        $body['aggs']['global'] = array_merge_recursive((array) $body['aggs']['global'], [
20
            'aggs'      => [$this->name => $nested]
21
        ]);
22
23
        // this field MUST NOT be array
24
        $body['aggs']['global']['global'] = (object) [];
25
26
        return $body;
27
    }
28
}
29