Passed
Push — master ( c1e68f...f0bd78 )
by Sam
01:33 queued 10s
created

StringIterator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 49
ccs 15
cts 15
cp 1
rs 10
c 1
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isNot() 0 3 1
A __construct() 0 3 1
A is() 0 3 1
A __toString() 0 3 1
A getRemainingAsString() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Badcow DNS Library.
7
 *
8
 * (c) Samuel Williams <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Badcow\DNS\Parser;
15
16
class StringIterator extends \ArrayIterator
17
{
18
    /**
19
     * StringIterator constructor.
20
     *
21
     * @param string $string
22
     */
23 39
    public function __construct(string $string = '')
24
    {
25 39
        parent::__construct(str_split($string));
26 39
    }
27
28
    /**
29
     * @param string $value
30
     *
31
     * @return bool
32
     */
33 39
    public function is(string $value): bool
34
    {
35 39
        return $value === $this->current();
36
    }
37
38
    /**
39
     * @param string $value
40
     *
41
     * @return bool
42
     */
43 39
    public function isNot(string $value): bool
44
    {
45 39
        return $value !== $this->current();
46
    }
47
48 4
    public function getRemainingAsString(): string
49
    {
50 4
        $string = '';
51 4
        while ($this->valid()) {
52 4
            $string .= $this->current();
53 4
            $this->next();
54
        }
55
56 4
        return $string;
57
    }
58
59
    /**
60
     * @return string
61
     */
62 12
    public function __toString()
63
    {
64 12
        return implode('', $this->getArrayCopy());
65
    }
66
}
67