Completed
Push — 2.0 ( 2c7009...c833bc )
by Marco
03:23
created

Iterator::current()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace Comodojo\Extender\Components;
2
3
/**
4
 * @package     Comodojo Framework
5
 * @author      Marco Giovinazzi <[email protected]>
6
 * @author      Marco Castiello <[email protected]>
7
 * @license     GPL-3.0+
8
 *
9
 * LICENSE:
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
trait Iterator {
26
27
    /**
28
     * Reset the iterator
29
     */
30
    public function rewind() {
31
32
        reset($this->data);
0 ignored issues
show
Bug introduced by
The property data does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33
34
    }
35
36
    /**
37
     * Get the current element
38
     *
39
     * @return mixed
40
     */
41
    public function current() {
42
43
        return current($this->data);
44
45
    }
46
47
    /**
48
     * Return the current key
49
     *
50
     * @return string|int
51
     */
52
    public function key() {
53
54
        return key($this->data);
55
56
    }
57
58
    /**
59
     * Move to next element
60
     */
61
    public function next() {
62
63
        return next($this->data);
64
65
    }
66
67
    /**
68
     * Check if element is valid (isset)
69
     *
70
     * @return boolean
71
     */
72
    public function valid() {
73
74
        return isset($this->data[$this->key()]);
75
76
    }
77
78
}
79