Completed
Pull Request — master (#555)
by Mantas
02:53
created

DocumentIterator::convertDocument()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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\ValueAggregation;
15
use ONGR\ElasticsearchBundle\Service\Manager;
16
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
17
18
/**
19
 * Class DocumentIterator.
20
 */
21
class DocumentIterator extends AbstractResultsIterator
22
{
23
    /**
24
     * @var array
25
     */
26
    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...
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function __construct(array $rawData, Manager $manager, array $scroll = [])
32
    {
33
        if (isset($rawData['aggregations'])) {
34
            $this->aggregations = $rawData['aggregations'];
35
            unset($rawData['aggregations']);
36
        }
37
38
        parent::__construct($rawData, $manager, $scroll);
39
    }
40
41
    /**
42
     * Get a specific aggregation by name. It fetches from the top level only.
43
     *
44
     * @param string $name
45
     *
46
     * @return ValueAggregation|null
47
     */
48 View Code Duplication
    public function getAggregation($name)
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...
49
    {
50
        // TODO: remove this *** after DSL update
51
        $name = AbstractAggregation::PREFIX . $name;
52
53
        if (!isset($this->aggregations[$name])) {
54
            return null;
55
        }
56
57
        return new ValueAggregation($this->aggregations[$name]);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    protected function convertDocument(array $document)
64
    {
65
        return $this->getConverter()->convertToDocument($document, $this->getManager());
66
    }
67
}
68