Passed
Branch master (30ae21)
by Gabor
03:15
created

IteratorTrait::next()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
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\Traits;
13
14
use WebHemi\Form\Element\FormElementInterface;
15
16
/**
17
 * Class IteratorTrait
18
 *
19
 * @codeCoverageIgnore - general implementation of the Iterator interface.
20
 */
21
trait IteratorTrait
22
{
23
    /** @var array<FormElementInterface> */
24
    protected $nodes = [];
25
26
    /**
27
     * Return the current element.
28
     *
29
     * @return FormElementInterface
30
     */
31
    public function current()
32
    {
33
        return current($this->nodes);
34
    }
35
36
    /**
37
     * Moves the pointer forward to next element.
38
     *
39
     * @return void
40
     */
41
    public function next()
42
    {
43
        next($this->nodes);
44
    }
45
46
    /**
47
     * Returns the key of the current element.
48
     *
49
     * @return mixed
50
     */
51
    public function key()
52
    {
53
        return key($this->nodes);
54
    }
55
56
    /**
57
     * Checks if current position is valid.
58
     *
59
     * @return boolean
60
     */
61
    public function valid()
62
    {
63
        $key = key($this->nodes);
64
65
        return ($key !== null && $key !== false);
66
    }
67
68
    /**
69
     * Rewinds the Iterator to the first element.
70
     *
71
     * @return void
72
     */
73
    public function rewind()
74
    {
75
        reset($this->nodes);
76
    }
77
}
78