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

Tokens   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 46
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A changeToken() 0 4 1
A current() 0 4 1
A key() 0 4 1
A next() 0 5 1
A rewind() 0 6 1
A valid() 0 4 1
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