ResourceRecordIterator::getRemainingAsString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 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 ResourceRecordIterator extends \ArrayIterator
17
{
18 33
    public function __construct(string $resourceRecord)
19
    {
20 33
        parent::__construct(explode(Tokens::SPACE, $resourceRecord));
21 33
    }
22
23
    /**
24
     * Return pointer to previous position.
25
     */
26 31
    public function prev(): void
27
    {
28 31
        if (!$this->valid()) {
29 1
            $this->end();
30
31 1
            return;
32
        }
33
34 31
        $this->seek((int) $this->key() - 1);
35 31
    }
36
37
    /**
38
     * Set pointer to the end of the array.
39
     */
40 1
    public function end(): void
41
    {
42 1
        $lastPos = $this->count() - 1;
43 1
        $this->seek($lastPos);
44 1
    }
45
46
    /**
47
     * Get all the remaining values of an iterator as an array. This will move the pointer to the end of the array.
48
     */
49 29
    public function getRemainingAsString(): string
50
    {
51 29
        $values = [];
52 29
        while ($this->valid()) {
53 29
            $values[] = $this->current();
54 29
            $this->next();
55
        }
56
57 29
        return implode(Tokens::SPACE, $values);
58
    }
59
60 4
    public function __toString(): string
61
    {
62 4
        return implode(Tokens::SPACE, $this->getArrayCopy());
63
    }
64
}
65