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

GlobalAggregationTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A wrapGlobal() 0 17 2
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