StringIterator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 57
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A is() 0 8 2
A isNot() 0 4 1
A getRemainingAsString() 0 10 2
A __toString() 0 4 1
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 44
    public function __construct(string $string = '')
22
    {
23 44
        parent::__construct(str_split($string));
24 44
    }
25
26 44
    /**
27
     * Test if current character is equal to a value, or (if $value is an array) is one of the values in the array.
28 44
     *
29
     * @param string|array $value test if current character is equal to, or is in, $value
30
     *
31 44
     * @return bool true if current character is, or is one of, the values
32
     */
33 44
    public function is($value): bool
34
    {
35
        if (is_array($value)) {
36 5
            return in_array($this->current(), $value);
37
        }
38 5
39 5
        return (string) $value === $this->current();
40 5
    }
41 5
42
    /**
43
     * Test if current character is not equal to a value, or (if $value is an array) is not any of the values in the array.
44 5
     *
45
     * @param string|array $value test if current character is not equal to, or is not any of, $value
46
     *
47
     * @return bool true if current character is not, or is not one of, the values
48
     */
49
    public function isNot($value): bool
50 15
    {
51
        return !$this->is($value);
52 15
    }
53
54
    public function getRemainingAsString(): string
55
    {
56
        $string = '';
57
        while ($this->valid()) {
58
            $string .= $this->current();
59
            $this->next();
60
        }
61
62
        return $string;
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public function __toString()
69
    {
70
        return implode('', $this->getArrayCopy());
71
    }
72
}
73