DocumentIterator::getAggregations()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 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
namespace ONGR\ElasticsearchBundle\Result;
13
14
use ONGR\ElasticsearchBundle\Result\Aggregation\AggregationValue;
15
16
class DocumentIterator extends AbstractResultsIterator
17
{
18
    public function getAggregations()
19
    {
20
        $aggregations = [];
21
22
        foreach (parent::getAggregations() as $key => $aggregation) {
23
            $aggregations[$key] = $this->getAggregation($key);
24
        }
25
26
        return $aggregations;
27
    }
28
29
    public function getAggregation($name)
30
    {
31
        $aggregations = parent::getAggregations();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getAggregations() instead of getAggregation()). Are you sure this is correct? If so, you might want to change this to $this->getAggregations().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
32
        if (!array_key_exists($name, $aggregations)) {
33
            return null;
34
        }
35
36
        return new AggregationValue($aggregations[$name]);
37
    }
38
39
    protected function convertDocument(array $raw)
40
    {
41
        $data = $raw['_source'] ?? $raw['_fields'] ?? null;
42
        $data['_id'] = $raw['_id'] ?? null;
43
44
        return $this->getConverter()->convertArrayToDocument($this->getIndex()->getNamespace(), $data);
45
    }
46
}
47