Completed
Push — master ( bd2156...bea8fa )
by Simonas
11s
created

DocumentIterator::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 2
eloc 5
nc 2
nop 3
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
/**
17
 * Class DocumentIterator.
18
 */
19
class DocumentIterator extends AbstractResultsIterator
20
{
21
    /**
22
     * Returns aggregations.
23
     *
24
     * @return array
25
     */
26
    public function getAggregations()
27
    {
28
        $aggregations = [];
29
30
        foreach (parent::getAggregations() as $key => $aggregation) {
31
            $aggregations[$key] = $this->getAggregation($key);
32
        }
33
34
        return $aggregations;
35
    }
36
37
    /**
38
     * Get a specific aggregation by name. It fetches from the top level only.
39
     *
40
     * @param string $name
41
     *
42
     * @return AggregationValue|null
43
     */
44
    public function getAggregation($name)
45
    {
46
        $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...
47
        if (!array_key_exists($name, $aggregations)) {
48
            return null;
49
        }
50
51
        return new AggregationValue($aggregations[$name]);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    protected function convertDocument(array $document)
58
    {
59
        return $this->getConverter()->convertToDocument($document, $this->getManager());
60
    }
61
}
62