Completed
Push — master ( 282f78...6dce89 )
by Sam
05:20
created

ResourceRecord::setTtl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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