Passed
Pull Request — master (#48)
by
unknown
07:52 queued 04:23
created

StringIterator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Zicht Online <http://zicht.nl>
4
 */
5
6
namespace Zicht\Itertools\lib;
7
8
use Zicht\Itertools\lib\Interfaces\FiniteIterableInterface;
9
use Zicht\Itertools\lib\Traits\FiniteIterableTrait;
10
11
class StringIterator implements FiniteIterableInterface
12
{
13
    use FiniteIterableTrait;
14
15
    /** @var string */
16
    protected $string;
17
18
    /** @var int */
19
    protected $key;
20
21
    /**
22
     * @param string $string
23
     */
24 8
    public function __construct($string)
25
    {
26 8
        $this->string = $string;
27 8
        $this->key = 0;
28 8
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 7
    public function rewind()
34
    {
35 7
        $this->key = 0;
36 7
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 4
    public function current()
42
    {
43 4
        return $this->string[$this->key];
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 4
    public function key()
50
    {
51 4
        return $this->key;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 4
    public function next()
58
    {
59 4
        $this->key += 1;
60 4
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 8
    public function valid()
66
    {
67 8
        return $this->key < strlen($this->string);
68
    }
69
}
70