Completed
Branch master (80ac3a)
by kacper
04:34 queued 51s
created

ConfigBuilder::withBinLogFileName()   A

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 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace MySQLReplication\Config;
4
5
/**
6
 * Class ConfigBuilder
7
 * @package MySQLReplication\Config
8
 */
9
class ConfigBuilder
10
{
11
    /**
12
     * @var string
13
     */
14
    private $user = '';
15
    /**
16
     * @var string
17
     */
18
    private $host = 'localhost';
19
    /**
20
     * @var int
21
     */
22
    private $port = 3306;
23
    /**
24
     * @var string
25
     */
26
    private $password = '';
27
    /**
28
     * @var string
29
     */
30
    private $charset = 'utf8';
31
    /**
32
     * @var string
33
     */
34
    private $gtid = '';
35
    /**
36
     * @var int
37
     */
38
    private $slaveId = 666;
39
    /**
40
     * @var string
41
     */
42
    private $binLogFileName = '';
43
    /**
44
     * @var int
45
     */
46
    private $binLogPosition = 0;
47
    /**
48
     * @var array
49
     */
50
    private $eventsOnly = [];
51
    /**
52
     * @var array
53
     */
54
    private $eventsIgnore = [];
55
    /**
56
     * @var array
57
     */
58
    private $tablesOnly = [];
59
    /**
60
     * @var array
61
     */
62
    private $databasesOnly = [];
63
    /**
64
     * @var string
65
     */
66
    private $mariaDbGtid = '';
67
    /**
68
     * @var int
69
     */
70
    private $tableCacheSize = 128;
71
    /**
72
     * @var array
73
     */
74
    private $custom = [];
75
    /**
76
     * @var int
77
     */
78
    private $heartbeatPeriod = 0;
79
80
    /**
81
     * @param string $user
82
     * @return ConfigBuilder
83
     */
84 56
    public function withUser($user)
85
    {
86 56
        $this->user = $user;
87
88 56
        return $this;
89
    }
90
91
    /**
92
     * @param string $host
93
     * @return ConfigBuilder
94
     */
95 56
    public function withHost($host)
96
    {
97 56
        $this->host = $host;
98
99 56
        return $this;
100
    }
101
102
    /**
103
     * @param int $port
104
     * @return ConfigBuilder
105
     */
106 2
    public function withPort($port)
107
    {
108 2
        $this->port = $port;
109
110 2
        return $this;
111
    }
112
113
    /**
114
     * @param string $password
115
     * @return ConfigBuilder
116
     */
117 56
    public function withPassword($password)
118
    {
119 56
        $this->password = $password;
120
121 56
        return $this;
122
    }
123
124
    /**
125
     * @param string $charset
126
     * @return ConfigBuilder
127
     */
128 2
    public function withCharset($charset)
129
    {
130 2
        $this->charset = $charset;
131
132 2
        return $this;
133
    }
134
135
    /**
136
     * @param string $gtid
137
     * @return ConfigBuilder
138
     */
139 2
    public function withGtid($gtid)
140
    {
141 2
        $this->gtid = $gtid;
142
143 2
        return $this;
144
    }
145
146
    /**
147
     * @param int $slaveId
148
     * @return ConfigBuilder
149
     */
150 2
    public function withSlaveId($slaveId)
151
    {
152 2
        $this->slaveId = $slaveId;
153
154 2
        return $this;
155
    }
156
157
    /**
158
     * @param string $binLogFileName
159
     * @return ConfigBuilder
160
     */
161 2
    public function withBinLogFileName($binLogFileName)
162
    {
163 2
        $this->binLogFileName = $binLogFileName;
164
165 2
        return $this;
166
    }
167
168
    /**
169
     * @param int $binLogPosition
170
     * @return ConfigBuilder
171
     */
172 2
    public function withBinLogPosition($binLogPosition)
173
    {
174 2
        $this->binLogPosition = $binLogPosition;
175
176 2
        return $this;
177
    }
178
179
    /**
180
     * @see ConstEventType
181
     * @param array $eventsOnly
182
     * @return ConfigBuilder
183
     */
184 5
    public function withEventsOnly(array $eventsOnly)
185
    {
186 5
        $this->eventsOnly = $eventsOnly;
187
188 5
        return $this;
189
    }
190
191
    /**
192
     * @see ConstEventType
193
     * @param array $eventsIgnore
194
     * @return ConfigBuilder
195
     */
196 56
    public function withEventsIgnore(array $eventsIgnore)
197
    {
198 56
        $this->eventsIgnore = $eventsIgnore;
199
200 56
        return $this;
201
    }
202
203
    /**
204
     * @param array $tablesOnly
205
     * @return ConfigBuilder
206
     */
207 3
    public function withTablesOnly(array $tablesOnly)
208
    {
209 3
        $this->tablesOnly = $tablesOnly;
210
211 3
        return $this;
212
    }
213
214
    /**
215
     * @param array $databasesOnly
216
     * @return ConfigBuilder
217
     */
218 2
    public function withDatabasesOnly(array $databasesOnly)
219
    {
220 2
        $this->databasesOnly = $databasesOnly;
221
222 2
        return $this;
223
    }
224
225
    /**
226
     * @param string $mariaDbGtid
227
     * @return ConfigBuilder
228
     */
229 2
    public function withMariaDbGtid($mariaDbGtid)
230
    {
231 2
        $this->mariaDbGtid = $mariaDbGtid;
232
233 2
        return $this;
234
    }
235
236
    /**
237
     * @param int $tableCacheSize
238
     * @return $this
239
     */
240 3
    public function withTableCacheSize($tableCacheSize)
241
    {
242 3
        $this->tableCacheSize = $tableCacheSize;
243
244 3
        return $this;
245
    }
246
247
    /**
248
     * @param array $custom
249
     * @return $this
250
     */
251 1
    public function withCustom(array $custom)
252
    {
253 1
        $this->custom = $custom;
254
255 1
        return $this;
256
    }
257
258
    /**
259
     * @see https://dev.mysql.com/doc/refman/5.6/en/change-master-to.html
260
     * @param int $heartbeatPeriod
261
     * @return $this
262
     */
263 4
    public function withHeartbeatPeriod($heartbeatPeriod)
264
    {
265 4
        $this->heartbeatPeriod = $heartbeatPeriod;
266
267 4
        return $this;
268
    }
269
270
    /**
271
     * @return Config
272
     */
273 73
    public function build()
274
    {
275 73
        return new Config(
276 73
            $this->user,
277 73
            $this->host,
278 73
            $this->port,
279 73
            $this->password,
280 73
            $this->charset,
281 73
            $this->gtid,
282 73
            $this->mariaDbGtid,
283 73
            $this->slaveId,
284 73
            $this->binLogFileName,
285 73
            $this->binLogPosition,
286 73
            $this->eventsOnly,
287 73
            $this->eventsIgnore,
288 73
            $this->tablesOnly,
289 73
            $this->databasesOnly,
290 73
            $this->tableCacheSize,
291 73
            $this->custom,
292 73
            $this->heartbeatPeriod
293 73
        );
294
    }
295
}