CNAME::getTarget()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
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\Rdata;
15
16
use Badcow\DNS\Message;
17
18
/**
19
 * @see https://tools.ietf.org/html/rfc1035#section-3.3.1
20
 */
21
class CNAME implements RdataInterface
22
{
23 1
    use RdataTrait;
24
25
    const TYPE = 'CNAME';
26
    const TYPE_CODE = 5;
27
28
    /**
29
     * @var string|null
30
     */
31
    protected $target;
32
33 45
    public function setTarget(string $target): void
34
    {
35 45
        $this->target = $target;
36 45
    }
37
38
    /**
39
     * @return string
40
     */
41 15
    public function getTarget(): ?string
42
    {
43 15
        return $this->target;
44
    }
45
46 13
    public function toText(): string
47
    {
48 13
        return $this->target ?? '';
49
    }
50
51 5
    public function toWire(): string
52
    {
53 5
        if (null === $this->target) {
54 1
            throw new \InvalidArgumentException('Target must be set.');
55
        }
56
57 5
        return Message::encodeName($this->target);
58
    }
59
60 17
    public function fromText(string $text): void
61
    {
62 17
        $this->setTarget($text);
63 17
    }
64
65 10
    public function fromWire(string $rdata, int &$offset = 0, ?int $rdLength = null): void
66
    {
67 10
        $this->setTarget(Message::decodeName($rdata, $offset));
68 10
    }
69
}
70