Completed
Push — master ( c0af29...92d223 )
by Simonas
16:22 queued 09:39
created

ArrayIterator::offsetExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
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\AggregationValue;
15
use ONGR\ElasticsearchBundle\Service\Manager;
16
17
/**
18
 * Class DocumentIterator.
19
 */
20
class ArrayIterator extends AbstractResultsIterator implements \ArrayAccess
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function offsetExists($offset)
26
    {
27
        return $this->documentExists($offset);
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function offsetGet($offset)
34
    {
35
        return $this->getDocument($offset);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function offsetSet($offset, $value)
42
    {
43
        $this->documents[$offset] = $value;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function offsetUnset($offset)
50
    {
51
        unset($this->documents[$offset]);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    protected function convertDocument(array $document)
58
    {
59
        if (array_key_exists('_source', $document)) {
60
            return $document['_source'];
61
        } elseif (array_key_exists('fields', $document)) {
62
            return array_map('reset', $document['fields']);
63
        }
64
65
        return $document;
66
    }
67
}
68