IterableTrait   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 92
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 4 1
A first() 0 4 1
A last() 0 4 1
A next() 0 4 1
A prev() 0 4 1
A key() 0 4 1
A valid() 0 4 1
A reset() 0 4 1
A rewind() 0 4 1
1
<?php
2
/**
3
 * File IterableTrait.php
4
 *
5
 * @author Edward Pfremmer <[email protected]>
6
 */
7
namespace Epfremme\Collection\Traits;
8
9
/**
10
 * Trait IterableTrait
11
 *
12
 * @property array|mixed[] $elements
13
 * @package Epfremme\Collection\Traits
14
 */
15
trait IterableTrait
16
{
17
    /**
18
     * Return the current element
19
     *
20
     * @return mixed
21
     */
22 8
    public function current()
23
    {
24 8
        return current($this->elements);
25
    }
26
27
    /**
28
     * Return the fist element
29
     *
30
     * @return mixed
31
     */
32 1
    public function first()
33
    {
34 1
        return reset($this->elements);
35
    }
36
37
    /**
38
     * Advance and return last element
39
     *
40
     * @return mixed
41
     */
42 4
    public function last()
43
    {
44 4
        return end($this->elements);
45
    }
46
47
    /**
48
     * Move elements pointer forward
49
     *
50
     * @return mixed
51
     */
52 4
    public function next()
53
    {
54 4
        return next($this->elements);
55
    }
56
57
    /**
58
     * Move elements pointer backward
59
     *
60
     * @reutrn void
61
     */
62 1
    public function prev()
63
    {
64 1
        return prev($this->elements);
65
    }
66
67
    /**
68
     * Return the key of the current element
69
     *
70
     * @return mixed
71
     */
72 6
    public function key()
73
    {
74 6
        return key($this->elements);
75
    }
76
77
    /**
78
     * Checks if current position is valid
79
     *
80
     * @return bool
81
     */
82 2
    public function valid()
83
    {
84 2
        return key($this->elements) !== null;
85
    }
86
87
    /**
88
     * Reset pointer and return the first element
89
     *
90
     * @return mixed
91
     */
92 2
    public function reset()
93
    {
94 2
        return reset($this->elements);
95
    }
96
97
    /**
98
     * Rewind the collection pointer
99
     *
100
     * @return void
101
     */
102 2
    public function rewind()
103
    {
104 2
        $this->reset();
105 2
    }
106
}
107