Passed
Branch master (8940db)
by Sam
02:38
created

RP::toText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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\Parser\Tokens;
17
18
/**
19
 * {@link https://tools.ietf.org/html/rfc1183}.
20
 */
21
class RP implements RdataInterface
22
{
23
    use RdataTrait;
24
25
    const TYPE = 'RP';
26
    const TYPE_CODE = 17;
27
28
    /**
29
     * @var string
30
     */
31
    private $mailboxDomainName;
32
33
    /**
34
     * @var string
35
     */
36
    private $txtDomainName;
37
38
    /**
39
     * @return string
40
     */
41
    public function getMailboxDomainName(): string
42
    {
43
        return $this->mailboxDomainName;
44
    }
45
46
    /**
47
     * @param string $mailboxDomainName
48
     */
49 2
    public function setMailboxDomainName(string $mailboxDomainName): void
50
    {
51 2
        $this->mailboxDomainName = $mailboxDomainName;
52 2
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getTxtDomainName(): string
58
    {
59
        return $this->txtDomainName;
60
    }
61
62
    /**
63
     * @param string $txtDomainName
64
     */
65 2
    public function setTxtDomainName(string $txtDomainName): void
66
    {
67 2
        $this->txtDomainName = $txtDomainName;
68 2
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73 1
    public function toText(): string
74
    {
75 1
        return sprintf('%s %s', $this->mailboxDomainName, $this->txtDomainName);
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81 1
    public function toWire(): string
82
    {
83 1
        return self::encodeName($this->mailboxDomainName).self::encodeName($this->txtDomainName);
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public static function fromText(string $text): RdataInterface
90
    {
91
        $rdata = explode(Tokens::SPACE, $text);
92
        $rp = new self();
93
        $rp->setMailboxDomainName($rdata[0]);
94
        $rp->setTxtDomainName($rdata[1]);
95
96
        return $rp;
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102 1
    public static function fromWire(string $rdata): RdataInterface
103
    {
104 1
        $pos = strpos($rdata, "\0");
105 1
        $mbox = substr($rdata, 0, $pos + 1);
106 1
        $txt = substr($rdata, $pos + 1);
107 1
        $rp = new self();
108 1
        $rp->setMailboxDomainName(self::decodeName($mbox));
109 1
        $rp->setTxtDomainName(self::decodeName($txt));
110
111 1
        return $rp;
112
    }
113
}
114