Passed
Branch dev-v4 (8aaafe)
by Sam
02:33
created

CNAME   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 62
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setTarget() 0 3 1
A getTarget() 0 3 1
A toText() 0 3 1
A fromText() 0 3 1
A fromWire() 0 3 1
A toWire() 0 7 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\Rdata;
15
16
/**
17
 * @see https://tools.ietf.org/html/rfc1035#section-3.3.1
18
 */
19
class CNAME implements RdataInterface
20
{
21
    use RdataTrait;
22
23
    const TYPE = 'CNAME';
24
    const TYPE_CODE = 5;
25
26
    /**
27
     * @var string|null
28
     */
29
    protected $target;
30
31
    /**
32
     * @param string $target
33
     */
34 42
    public function setTarget(string $target): void
35
    {
36 42
        $this->target = $target;
37 42
    }
38
39
    /**
40
     * @return string
41
     */
42 15
    public function getTarget(): ?string
43
    {
44 15
        return $this->target;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 10
    public function toText(): string
51
    {
52 10
        return $this->target ?? '';
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 5
    public function toWire(): string
59
    {
60 5
        if (null === $this->target) {
61 1
            throw new \InvalidArgumentException('Target must be set.');
62
        }
63
64 5
        return self::encodeName($this->target);
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 14
    public function fromText(string $text): void
71
    {
72 14
        $this->setTarget($text);
73 14
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78 10
    public function fromWire(string $rdata, int &$offset = 0, ?int $rdLength = null): void
79
    {
80 10
        $this->setTarget(self::decodeName($rdata, $offset));
81 10
    }
82
}
83