LazyIterator::key()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Zurbaev\ApiClient\Traits;
4
5
/**
6
 * Trait LazyIterator
7
 *
8
 * @property array $keys
9
 * @property array $items
10
 * @property int $position
11
 */
12
trait LazyIterator
13
{
14
    /**
15
     * Performs lazy load checks and loads items if required.
16
     */
17
    abstract protected function checkLazyLoad();
18
19
    /**
20
     * Current iterator item.
21
     *
22
     * @return mixed|null
23
     */
24 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...
25
    {
26
        $this->checkLazyLoad();
27
28
        $currentKey = $this->keys[$this->position];
29
30
        return isset($this->items[$currentKey]) ? $this->items[$currentKey] : null;
31
    }
32
33
    /**
34
     * Current iterator position.
35
     *
36
     * @return mixed
37
     */
38
    public function key()
39
    {
40
        $this->checkLazyLoad();
41
42
        return $this->keys[$this->position];
43
    }
44
45
    /**
46
     * Increments iterator position.
47
     */
48
    public function next()
49
    {
50
        $this->checkLazyLoad();
51
52
        $this->position++;
53
    }
54
55
    /**
56
     * Rewinds iterator back to first position.
57
     */
58
    public function rewind()
59
    {
60
        $this->checkLazyLoad();
61
62
        $this->position = 0;
63
    }
64
65
    /**
66
     * Determines if there is some value at current iterator position.
67
     *
68
     * @return bool
69
     */
70 View Code Duplication
    public function valid()
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...
71
    {
72
        $this->checkLazyLoad();
73
74
        if (!isset($this->keys[$this->position])) {
75
            return false;
76
        }
77
78
        $currentKey = $this->keys[$this->position];
79
80
        return isset($this->items[$currentKey]);
81
    }
82
}
83