Completed
Pull Request — 5.0 (#775)
by Michael
15:21
created

ObjectCallbackIterator::current()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
c 0
b 0
f 0
rs 9.4285
cc 3
eloc 7
nc 2
nop 0
1
<?php
2
3
namespace ONGR\ElasticsearchBundle\Result;
4
5
class ObjectCallbackIterator extends \ArrayIterator
6
{
7
    /**
8
     * @var \Closure
9
     */
10
    private $callback;
11
12
    /**
13
     * Converts array data to document objects via the callback function.
14
     *
15
     * @param \Closure $callback
16
     * @param array $array
17
     */
18
    public function __construct(\Closure $callback, array $array = array())
19
    {
20
        $this->callback = $callback;
21
22
        parent::__construct($array);
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 View Code Duplication
    public function current()
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...
29
    {
30
        $value = parent::current();
31
32
        // Generate objects on demand
33
        if ($value === null && $this->valid()) {
34
            $key = $this->key();
35
            $callback = $this->callback;
36
            return $callback($key);
37
        }
38
39
        return $value;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 View Code Duplication
    public function offsetGet($offset)
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...
46
    {
47
        $value = parent::offsetGet($offset);
48
49
        // Generate objects on demand
50
        if ($value === null && $this->valid()) {
51
            $callback = $this->callback;
52
            return $callback($offset);
53
        }
54
55
        return $value;
56
    }
57
}
58