ResourceRecordIterator::end()   A
last analyzed

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
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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 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