IteratorTrait::key()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SubjectivePHP\Spl\Traits;
4
5
trait IteratorTrait
6
{
7
    /**
8
     * Rewind the Iterator to the first element
9
     *
10
     * @return void
11
     */
12
    public function rewind()
13
    {
14
        reset($this->container);
0 ignored issues
show
Bug introduced by
The property container 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...
15
    }
16
17
    /**
18
     * Return the current element.
19
     *
20
     * @return mixed
21
     */
22
    public function current()
23
    {
24
        return current($this->container);
25
    }
26
27
    /**
28
     * Return the key of the current element
29
     *
30
     * @return mixed
31
     */
32
    public function key()
33
    {
34
        return key($this->container);
35
    }
36
37
    /**
38
     * Move forward to next element.
39
     *
40
     * @return void
41
     */
42
    public function next()
43
    {
44
        next($this->container);
45
    }
46
47
    /**
48
     * Checks if current position is valid.
49
     *
50
     * @return boolean
51
     */
52
    public function valid()
53
    {
54
        return current($this->container) !== false;
55
    }
56
}
57