RP::fromText()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
use Badcow\DNS\Parser\Tokens;
18
19
/**
20
 * {@link https://tools.ietf.org/html/rfc1183}.
21
 */
22
class RP implements RdataInterface
23
{
24 1
    use RdataTrait;
25
26
    const TYPE = 'RP';
27
    const TYPE_CODE = 17;
28
29
    /**
30
     * @var string
31
     */
32
    private $mailboxDomainName;
33
34
    /**
35
     * @var string
36
     */
37
    private $txtDomainName;
38
39 1
    public function getMailboxDomainName(): string
40
    {
41 1
        return $this->mailboxDomainName;
42
    }
43
44 5
    public function setMailboxDomainName(string $mailboxDomainName): void
45
    {
46 5
        $this->mailboxDomainName = $mailboxDomainName;
47 5
    }
48
49 1
    public function getTxtDomainName(): string
50
    {
51 1
        return $this->txtDomainName;
52
    }
53
54 5
    public function setTxtDomainName(string $txtDomainName): void
55
    {
56 5
        $this->txtDomainName = $txtDomainName;
57 5
    }
58
59 3
    public function toText(): string
60
    {
61 3
        return sprintf('%s %s', $this->mailboxDomainName, $this->txtDomainName);
62
    }
63
64 1
    public function toWire(): string
65
    {
66 1
        return Message::encodeName($this->mailboxDomainName).Message::encodeName($this->txtDomainName);
67
    }
68
69 1
    public function fromText(string $text): void
70
    {
71 1
        $rdata = explode(Tokens::SPACE, $text);
72 1
        $this->setMailboxDomainName($rdata[0]);
73 1
        $this->setTxtDomainName($rdata[1]);
74 1
    }
75
76 1
    public function fromWire(string $rdata, int &$offset = 0, ?int $rdLength = null): void
77
    {
78 1
        $this->setMailboxDomainName(Message::decodeName($rdata, $offset));
79 1
        $this->setTxtDomainName(Message::decodeName($rdata, $offset));
80 1
    }
81
}
82