Test Setup Failed
Pull Request — master (#32)
by
unknown
05:29
created

RecordAppender::appendSoaRecord()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 3
cts 3
cp 1
rs 9.536
c 0
b 0
f 0
cc 1
nc 1
nop 8
crap 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * @author: Viskov Sergey
4
 * @date  : 4/12/16
5
 * @time  : 1:00 PM
6
 */
7
8
namespace LTDBeget\dns\configurator\zoneEntities;
9
10
use LTDBeget\dns\configurator\zoneEntities\record\AaaaRecord;
11
use LTDBeget\dns\configurator\zoneEntities\record\ARecord;
12
use LTDBeget\dns\configurator\zoneEntities\record\CaaRecord;
13
use LTDBeget\dns\configurator\zoneEntities\record\CnameRecord;
14
use LTDBeget\dns\configurator\zoneEntities\record\MxRecord;
15
use LTDBeget\dns\configurator\zoneEntities\record\NaptrRecord;
16
use LTDBeget\dns\configurator\zoneEntities\record\NsRecord;
17
use LTDBeget\dns\configurator\zoneEntities\record\PtrRecord;
18
use LTDBeget\dns\configurator\zoneEntities\record\SoaRecord;
19
use LTDBeget\dns\configurator\zoneEntities\record\SrvRecord;
20
use LTDBeget\dns\configurator\zoneEntities\record\TxtRecord;
21
22
/**
23
 * Class RecordAppender
24
 *
25
 * @package LTDBeget\dns\configurator\zoneEntities
26
 */
27
class RecordAppender
28
{
29
    /**
30
     * @var Node
31
     */
32
    protected $node;
33
34
    /**
35
     * Default value for ttl,
36
     * that will be set if no ttl given
37
     *
38
     * @var int
39
     */
40
    protected $defaultTtl = 600;
41
42
    /**
43 1
     * @param Node $node
44
     */
45 1
    public function __construct(Node $node)
46 1
    {
47
        $this->node = $node;
48
    }
49
50
    /**
51
     * @param string   $address
52
     * @param int|null $ttl
53 1
     * @return ARecord
54
     */
55 1
    public function appendARecord(string $address, int $ttl = NULL) : ARecord
56
    {
57
        return new ARecord($this->node, $ttl ?? $this->defaultTtl, $address);
58
    }
59
60
    /**
61
     * @param string   $address
62
     * @param int|null $ttl
63 1
     * @return AaaaRecord
64
     */
65 1
    public function appendAaaaRecord(string $address, int $ttl = NULL) : AaaaRecord
66
    {
67
        return new AaaaRecord($this->node, $ttl ?? $this->defaultTtl, $address);
68
    }
69
70
    /**
71
     * @param string   $cname
72
     * @param int|null $ttl
73 1
     * @return CnameRecord
74
     */
75 1
    public function appendCNameRecord(string $cname, int $ttl = NULL) : CnameRecord
76
    {
77
        return new CnameRecord($this->node, $ttl ?? $this->defaultTtl, $cname);
78
    }
79
80
    /**
81
     * @param int      $preference
82
     * @param string   $exchange
83
     * @param int|null $ttl
84 1
     * @return MxRecord
85
     */
86 1
    public function appendMxRecord(int $preference, string $exchange, int $ttl = NULL) : MxRecord
87
    {
88
        return new MxRecord($this->node, $ttl ?? $this->defaultTtl, $preference, $exchange);
89
    }
90
91
    /**
92
     * @param string   $nsdName
93
     * @param int|null $ttl
94 1
     * @return NsRecord
95
     */
96 1
    public function appendNsRecord(string $nsdName, int $ttl = NULL) : NsRecord
97
    {
98
        return new NsRecord($this->node, $ttl ?? $this->defaultTtl, $nsdName);
99
    }
100
101
    /**
102
     * @param string   $ptrDName
103
     * @param int|null $ttl
104 1
     * @return PtrRecord
105
     */
106 1
    public function appendPtrRecord(string $ptrDName, int $ttl = NULL) : PtrRecord
107
    {
108
        return new PtrRecord($this->node, $ttl ?? $this->defaultTtl, $ptrDName);
109
    }
110
111
    /**
112
     * @param          $mName
113
     * @param          $rName
114
     * @param          $serial
115
     * @param          $refresh
116
     * @param          $retry
117
     * @param          $expire
118
     * @param          $minimum
119
     * @param int|null $ttl
120 1
     * @return SoaRecord
121
     */
122
    public function appendSoaRecord
123
    (
124
        string $mName,
125
        string $rName,
126
        int $serial,
127
        int $refresh,
128
        int $retry,
129
        int $expire,
130
        int $minimum,
131
        int $ttl = NULL
132 1
    ) : SoaRecord
133 1
    {
134 1
        return new SoaRecord(
135
            $this->node,
136
            $ttl ?? $this->defaultTtl,
137
            $mName,
138
            $rName,
139
            $serial,
140
            $refresh,
141
            $retry,
142
            $expire,
143
            $minimum
144
        );
145
    }
146
147
    /**
148
     * @param int      $priority
149
     * @param int      $weight
150
     * @param int      $port
151
     * @param string   $target
152
     * @param int|null $ttl
153 1
     * @return SrvRecord
154
     */
155
    public function appendSrvRecord
156
    (
157
        int $priority,
158
        int $weight,
159
        int $port,
160
        string $target,
161
        int $ttl = NULL
162 1
    ) : SrvRecord
163
    {
164
        return new SrvRecord($this->node, $ttl ?? $this->defaultTtl, $priority, $weight, $port, $target);
165
    }
166
167
    /**
168
     * @param string   $txtData
169
     * @param int|null $ttl
170 1
     * @return TxtRecord
171
     */
172 1
    public function appendTxtRecord(string $txtData, int $ttl = NULL) : TxtRecord
173
    {
174
        return new TxtRecord($this->node, $ttl ?? $this->defaultTtl, $txtData);
175
    }
176
177
    /**
178
     * @param int      $flags
179
     * @param string   $tag
180
     * @param string   $value
181
     * @param int|NULL $ttl
182
     *
183
     * @return CaaRecord
184
     */
185
    public function appendCaaRecord(int $flags, string $tag, string $value, int $ttl = NULL) : CaaRecord
186
    {
187
        return new CaaRecord($this->node, $ttl ?? $this->defaultTtl, $flags, $tag, $value);
188
    }
189
190
    /**
191
     * @param int      $order
192
     * @param int      $preference
193
     * @param string   $flags
194
     * @param string   $services
195
     * @param string   $regexp
196
     * @param string   $replacement
197
     * @param int|NULL $ttl
198
     *
199
     * @return NaptrRecord
200
     */
201
    public function appendNaptrRecord(int $order, int $preference, string $flags, string $services,
202
                                      string $regexp, string $replacement, int $ttl = NULL) : NaptrRecord
203
    {
204
        return new NaptrRecord($this->node, $ttl ?? $this->defaultTtl,
205
            $order, $preference, $flags, $services, $regexp, $replacement);
206
    }
207
}
208