Completed
Push — master ( 73de08...39d3cf )
by Gabor
03:53
created

IteratorTrait::key()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 5.6
6
 *
7
 * @copyright 2012 - 2016 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link      http://www.gixx-web.com
11
 */
12
namespace WebHemi\Form\Element\Traits;
13
14
use WebHemi\Form\Element\FormElementInterface;
15
16
/**
17
 * Class IteratorTrait
18
 */
19
trait IteratorTrait
20
{
21
    /** @var array<FormElementInterface> */
22
    protected $nodes = [];
23
24
    /**
25
     * Return the current element.
26
     *
27
     * @return FormElementInterface
28
     */
29
    public function current()
30
    {
31
        return current($this->nodes);
32
    }
33
34
    /**
35
     * Moves the pointer forward to next element.
36
     *
37
     * @return void
38
     */
39
    public function next()
40
    {
41
        next($this->nodes);
42
    }
43
44
    /**
45
     * Returns the key of the current element.
46
     *
47
     * @return mixed
48
     */
49
    public function key()
50
    {
51
        return key($this->nodes);
52
    }
53
54
    /**
55
     * Checks if current position is valid.
56
     *
57
     * @return boolean
58
     */
59
    public function valid()
60
    {
61
        $key = key($this->nodes);
62
63
        return ($key !== null && $key !== false);
64
    }
65
66
    /**
67
     * Rewinds the Iterator to the first element.
68
     *
69
     * @return void
70
     */
71
    public function rewind()
72
    {
73
        reset($this->nodes);
74
    }
75
}
76