InternalIteratorTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 75
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 4 1
A next() 0 4 1
A key() 0 4 1
A valid() 0 4 1
A rewind() 0 7 2
1
<?php
2
3
namespace RayRutjes\GetEventStore\Util;
4
5
trait InternalIteratorTrait
6
{
7
    /**
8
     * @var \Iterator
9
     */
10
    protected $iterator;
11
12
    /**
13
     * Return the current element.
14
     *
15
     * @link  http://php.net/manual/en/iterator.current.php
16
     *
17
     * @return mixed Can return any type.
18
     *
19
     * @since 5.0.0
20
     */
21
    public function current()
22
    {
23
        return $this->iterator->current();
24
    }
25
26
    /**
27
     * Move forward to next element.
28
     *
29
     * @link  http://php.net/manual/en/iterator.next.php
30
     * @since 5.0.0
31
     */
32
    public function next()
33
    {
34
        $this->iterator->next();
35
    }
36
37
    /**
38
     * Return the key of the current element.
39
     *
40
     * @link  http://php.net/manual/en/iterator.key.php
41
     *
42
     * @return mixed scalar on success, or null on failure.
43
     *
44
     * @since 5.0.0
45
     */
46
    public function key()
47
    {
48
        return $this->iterator->key();
49
    }
50
51
    /**
52
     * Checks if current position is valid.
53
     *
54
     * @link  http://php.net/manual/en/iterator.valid.php
55
     *
56
     * @return bool The return value will be casted to boolean and then evaluated.
57
     *              Returns true on success or false on failure.
58
     *
59
     * @since 5.0.0
60
     */
61
    public function valid()
62
    {
63
        return $this->iterator->valid();
64
    }
65
66
    /**
67
     * Rewind the Iterator to the first element.
68
     *
69
     * @link  http://php.net/manual/en/iterator.rewind.php
70
     * @since 5.0.0
71
     */
72
    public function rewind()
73
    {
74
        if (null === $this->iterator) {
75
            throw new \LogicException('Missing internal iterator.');
76
        }
77
        $this->iterator->rewind();
78
    }
79
}
80