Completed
Push — 1.0 ( f45751...770e00 )
by Simonas
12:41 queued 10:12
created

DocumentIterator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 7
c 4
b 0
f 0
lcom 1
cbo 3
dl 0
loc 60
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A getAggregations() 0 10 2
A getAggregation() 0 8 2
A convertDocument() 0 4 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\AggregationValue;
15
use ONGR\ElasticsearchBundle\Service\Manager;
16
17
/**
18
 * Class DocumentIterator.
19
 */
20
class DocumentIterator 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
    public function __construct(array $rawData, Manager $manager, array $scroll = [])
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
        $aggregations = array();
48
49
        foreach ($this->aggregations as $key => $aggregation) {
50
            $aggregations[$key] = $this->getAggregation($key);
51
        }
52
53
        return $aggregations;
54
    }
55
56
    /**
57
     * Get a specific aggregation by name. It fetches from the top level only.
58
     *
59
     * @param string $name
60
     *
61
     * @return AggregationValue|null
62
     */
63
    public function getAggregation($name)
64
    {
65
        if (!isset($this->aggregations[$name])) {
66
            return null;
67
        }
68
69
        return new AggregationValue($this->aggregations[$name]);
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    protected function convertDocument(array $document)
76
    {
77
        return $this->getConverter()->convertToDocument($document, $this->getManager());
78
    }
79
}
80