ResourceRecord::setTtl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
/*
4
 * This file is part of PHP DNS Server.
5
 *
6
 * (c) Yif Swery <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace yswery\DNS;
13
14
class ResourceRecord
15
{
16
    /**
17
     * @var string
18
     */
19
    private $name;
20
21
    /**
22
     * @var int
23
     */
24
    private $type;
25
26
    /**
27
     * @var int
28
     */
29
    private $ttl;
30
31
    /**
32
     * @var string|array
33
     */
34
    private $rdata;
35
36
    /**
37
     * @var int
38
     */
39
    private $class = ClassEnum::INTERNET;
40
41
    /**
42
     * @var bool
43
     */
44
    private $question = false;
45
46
    /**
47
     * @return string
48
     */
49 45
    public function getName(): string
50
    {
51 45
        return $this->name;
52
    }
53
54
    /**
55
     * @param string $name
56
     *
57
     * @return ResourceRecord
58
     */
59 47
    public function setName(string $name): ResourceRecord
60
    {
61 47
        $this->name = $name;
62
63 47
        return $this;
64
    }
65
66
    /**
67
     * @return int
68
     */
69 46
    public function getType(): int
70
    {
71 46
        return $this->type;
72
    }
73
74
    /**
75
     * @param int $type
76
     *
77
     * @return ResourceRecord
78
     */
79 47
    public function setType(int $type): ResourceRecord
80
    {
81 47
        $this->type = $type;
82
83 47
        return $this;
84
    }
85
86
    /**
87
     * @return int
88
     */
89 6
    public function getTtl(): int
90
    {
91 6
        return $this->ttl;
92
    }
93
94
    /**
95
     * @param int $ttl
96
     *
97
     * @return ResourceRecord
98
     */
99 45
    public function setTtl(int $ttl): ResourceRecord
100
    {
101 45
        $this->ttl = $ttl;
102
103 45
        return $this;
104
    }
105
106
    /**
107
     * @return array|string
108
     */
109 8
    public function getRdata()
110
    {
111 8
        return $this->rdata;
112
    }
113
114
    /**
115
     * @param array|string $rdata
116
     *
117
     * @return ResourceRecord
118
     */
119 45
    public function setRdata($rdata): ResourceRecord
120
    {
121 45
        $this->rdata = $rdata;
122
123 45
        return $this;
124
    }
125
126
    /**
127
     * @return int
128
     */
129 45
    public function getClass(): int
130
    {
131 45
        return $this->class;
132
    }
133
134
    /**
135
     * @param int $class
136
     *
137
     * @return ResourceRecord
138
     */
139 46
    public function setClass(int $class): ResourceRecord
140
    {
141 46
        $this->class = $class;
142
143 46
        return $this;
144
    }
145
146
    /**
147
     * @return bool
148
     */
149 10
    public function isQuestion(): bool
150
    {
151 10
        return $this->question;
152
    }
153
154
    /**
155
     * @param bool $question
156
     *
157
     * @return ResourceRecord
158
     */
159 32
    public function setQuestion(bool $question): ResourceRecord
160
    {
161 32
        $this->question = $question;
162
163 32
        return $this;
164
    }
165
166
    /**
167
     * @return string
168
     */
169
    public function __toString()
170
    {
171
        if (is_array($this->rdata)) {
172
            $rdata = '(';
173
            foreach ($this->rdata as $key => $value) {
174
                $rdata .= $key.': '.$value.', ';
175
            }
176
            $rdata = rtrim($rdata, ', ').')';
177
        } else {
178
            $rdata = $this->rdata;
179
        }
180
181
        return sprintf(
182
            '%s %s %s %s %s',
183
            $this->name,
184
            RecordTypeEnum::getName($this->type),
185
            ClassEnum::getName($this->class),
186
            $this->ttl,
187
            $rdata
188
        );
189
    }
190
}
191