Completed
Push — master ( 2391a8...1d9387 )
by Garrett
02:10
created

Tokens::rewind()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4286
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace StringObject\Decorator;
4
5
use StringObject\StrObj;
6
7
class Tokens implements \Iterator
8
{
9
    private $strobj;
10
    private $delim;
11
    private $index = 0;
12
    private $curval;
13
14
    public function __construct(StrObj $strobj, $delim)
15
    {
16
        $this->strobj = $strobj;
17
        $this->delim = $delim;
18
    }
19
20
    public function changeToken($delim)
21
    {
22
        $this->delim = $delim;
23
    }
24
25
    public function current()
26
    {
27
        return $this->curval;
28
    }
29
30
    public function key()
31
    {
32
        return $this->index;
33
    }
34
35
    public function next()
36
    {
37
        $this->curval = $this->strobj->nextToken($this->delim);
38
        $this->index++;
39
    }
40
41
    public function rewind()
42
    {
43
        $this->strobj->resetToken();
44
        $this->curval = $this->strobj->nextToken($this->delim);
45
        $this->index = 0;
46
    }
47
48
    public function valid()
49
    {
50
        return ($this->curval !== false);
51
    }
52
}
53