Completed
Push — master ( 9d1314...5291f6 )
by kacper
02:05
created

ConfigBuilder::withCharset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
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
    /**
73
     * @param string $user
74
     * @return ConfigBuilder
75
     */
76
    public function withUser($user)
77
    {
78
        $this->user = $user;
79
80
        return $this;
81
    }
82
83
    /**
84
     * @param string $host
85
     * @return ConfigBuilder
86
     */
87
    public function withHost($host)
88
    {
89
        $this->host = $host;
90
91
        return $this;
92
    }
93
94
    /**
95
     * @param int $port
96
     * @return ConfigBuilder
97
     */
98
    public function withPort($port)
99
    {
100
        $this->port = $port;
101
102
        return $this;
103
    }
104
105
    /**
106
     * @param string $password
107
     * @return ConfigBuilder
108
     */
109
    public function withPassword($password)
110
    {
111
        $this->password = $password;
112
113
        return $this;
114
    }
115
116
    /**
117
     * @param string $charset
118
     * @return ConfigBuilder
119
     */
120
    public function withCharset($charset)
121
    {
122
        $this->charset = $charset;
123
124
        return $this;
125
    }
126
127
    /**
128
     * @param string $gtid
129
     * @return ConfigBuilder
130
     */
131
    public function withGtid($gtid)
132
    {
133
        $this->gtid = $gtid;
134
135
        return $this;
136
    }
137
138
    /**
139
     * @param int $slaveId
140
     * @return ConfigBuilder
141
     */
142
    public function withSlaveId($slaveId)
143
    {
144
        $this->slaveId = $slaveId;
145
146
        return $this;
147
    }
148
149
    /**
150
     * @param string $binLogFileName
151
     * @return ConfigBuilder
152
     */
153
    public function withBinLogFileName($binLogFileName)
154
    {
155
        $this->binLogFileName = $binLogFileName;
156
157
        return $this;
158
    }
159
160
    /**
161
     * @param int $binLogPosition
162
     * @return ConfigBuilder
163
     */
164
    public function withBinLogPosition($binLogPosition)
165
    {
166
        $this->binLogPosition = $binLogPosition;
167
168
        return $this;
169
    }
170
171
    /**
172
     * @param array $eventsOnly
173
     * @return ConfigBuilder
174
     */
175
    public function withEventsOnly(array $eventsOnly)
176
    {
177
        $this->eventsOnly = $eventsOnly;
178
179
        return $this;
180
    }
181
182
    /**
183
     * @param array $eventsIgnore
184
     * @return ConfigBuilder
185
     */
186
    public function withEventsIgnore(array $eventsIgnore)
187
    {
188
        $this->eventsIgnore = $eventsIgnore;
189
190
        return $this;
191
    }
192
193
    /**
194
     * @param array $tablesOnly
195
     * @return ConfigBuilder
196
     */
197
    public function withTablesOnly(array $tablesOnly)
198
    {
199
        $this->tablesOnly = $tablesOnly;
200
201
        return $this;
202
    }
203
204
    /**
205
     * @param array $databasesOnly
206
     * @return ConfigBuilder
207
     */
208
    public function withDatabasesOnly(array $databasesOnly)
209
    {
210
        $this->databasesOnly = $databasesOnly;
211
212
        return $this;
213
    }
214
215
    /**
216
     * @param string $mariaDbGtid
217
     * @return ConfigBuilder
218
     */
219
    public function withMariaDbGtid($mariaDbGtid)
220
    {
221
        $this->mariaDbGtid = $mariaDbGtid;
222
223
        return $this;
224
    }
225
226
    /**
227
     * @param int $tableCacheSize
228
     */
229
    public function withTableCacheSize($tableCacheSize)
230
    {
231
        $this->tableCacheSize = $tableCacheSize;
232
    }
233
234
    /**
235
     * @return Config
236
     */
237
    public function build()
238
    {
239
        return new Config(
240
            $this->user,
241
            $this->host,
242
            $this->port,
243
            $this->password,
244
            $this->charset,
245
            $this->gtid,
246
            $this->mariaDbGtid,
247
            $this->slaveId,
248
            $this->binLogFileName,
249
            $this->binLogPosition,
250
            $this->eventsOnly,
251
            $this->eventsIgnore,
252
            $this->tablesOnly,
253
            $this->databasesOnly,
254
            $this->tableCacheSize
255
        );
256
    }
257
}