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