Completed
Pull Request — master (#678)
by Simonas
03:02
created

ArrayIterator::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 9
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
use ONGR\ElasticsearchBundle\Service\Manager;
16
17
/**
18
 * Class DocumentIterator.
19
 */
20
class ArrayIterator extends AbstractResultsIterator
21
{
22
    /**
23
     * @var array
24
     */
25
    private $aggregations;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 View Code Duplication
    public function __construct(array $rawData, Manager $manager, array $scroll = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32
        if (isset($rawData['aggregations'])) {
33
            $this->aggregations = $rawData['aggregations'];
34
            unset($rawData['aggregations']);
35
        }
36
37
        parent::__construct($rawData, $manager, $scroll);
38
    }
39
40
    /**
41
     * Returns aggregations.
42
     *
43
     * @return array
44
     */
45
    public function getAggregations()
46
    {
47
        return $this->aggregations;
48
    }
49
50
    /**
51
     * Get a specific aggregation by name. It fetches from the top level only.
52
     *
53
     * @param string $name
54
     *
55
     * @return AggregationValue|null
56
     */
57
    public function getAggregation($name)
58
    {
59
        if (!isset($this->aggregations[$name])) {
60
            return null;
61
        }
62
63
        return $this->aggregations[$name];
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    protected function convertDocument(array $document)
70
    {
71
        return $document;
72
    }
73
}
74