Completed
Pull Request — master (#53)
by kacper
06:58 queued 48s
created

ConfigBuilder::withPassword()   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 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace MySQLReplication\Config;
5
6
class ConfigBuilder
7
{
8
    private $user = '';
9
    private $host = 'localhost';
10
    private $port = 3306;
11
    private $password = '';
12
    private $charset = 'utf8';
13
    private $gtid = '';
14
    private $slaveId = 666;
15
    private $binLogFileName = '';
16
    private $binLogPosition = 0;
17
    private $eventsOnly = [];
18
    private $eventsIgnore = [];
19
    private $tablesOnly = [];
20
    private $databasesOnly = [];
21
    private $mariaDbGtid = '';
22
    private $tableCacheSize = 128;
23
    private $custom = [];
24
    private $heartbeatPeriod = 0;
25
26 56
    public function withUser(string $user): self
27
    {
28 56
        $this->user = $user;
29
30 56
        return $this;
31
    }
32
33 57
    public function withHost(string $host): self
34
    {
35 57
        $this->host = $host;
36
37 57
        return $this;
38
    }
39
40 57
    public function withPort(int $port): self
41
    {
42 57
        $this->port = $port;
43
44 57
        return $this;
45
    }
46
47 56
    public function withPassword(string $password): self
48
    {
49 56
        $this->password = $password;
50
51 56
        return $this;
52
    }
53
54
    public function withCharset(string $charset): self
55
    {
56
        $this->charset = $charset;
57
58
        return $this;
59
    }
60
61 1
    public function withGtid(string $gtid): self
62
    {
63 1
        $this->gtid = $gtid;
64
65 1
        return $this;
66
    }
67
68 1
    public function withSlaveId(int $slaveId): self
69
    {
70 1
        $this->slaveId = $slaveId;
71
72 1
        return $this;
73
    }
74
75
    public function withBinLogFileName(string $binLogFileName): self
76
    {
77
        $this->binLogFileName = $binLogFileName;
78
79
        return $this;
80
    }
81
82 1
    public function withBinLogPosition(int $binLogPosition): self
83
    {
84 1
        $this->binLogPosition = $binLogPosition;
85
86 1
        return $this;
87
    }
88
89 5
    public function withEventsOnly(array $eventsOnly): self
90
    {
91 5
        $this->eventsOnly = $eventsOnly;
92
93 5
        return $this;
94
    }
95
96 57
    public function withEventsIgnore(array $eventsIgnore): self
97
    {
98 57
        $this->eventsIgnore = $eventsIgnore;
99
100 57
        return $this;
101
    }
102
103 2
    public function withTablesOnly(array $tablesOnly): self
104
    {
105 2
        $this->tablesOnly = $tablesOnly;
106
107 2
        return $this;
108
    }
109
110 1
    public function withDatabasesOnly(array $databasesOnly): self
111
    {
112 1
        $this->databasesOnly = $databasesOnly;
113
114 1
        return $this;
115
    }
116
117
    public function withMariaDbGtid(string $mariaDbGtid): self
118
    {
119
        $this->mariaDbGtid = $mariaDbGtid;
120
121
        return $this;
122
    }
123
124
125 2
    public function withTableCacheSize(int $tableCacheSize): self
126
    {
127 2
        $this->tableCacheSize = $tableCacheSize;
128
129 2
        return $this;
130
    }
131
132
133
    public function withCustom(array $custom): self
134
    {
135
        $this->custom = $custom;
136
137
        return $this;
138
    }
139
140
    /**
141
     * @see https://dev.mysql.com/doc/refman/5.6/en/change-master-to.html
142
     */
143 2
    public function withHeartbeatPeriod(int $heartbeatPeriod): self
144
    {
145 2
        $this->heartbeatPeriod = $heartbeatPeriod;
146
147 2
        return $this;
148
    }
149
150 68
    public function build(): Config
151
    {
152 68
        return new Config(
153 68
            $this->user,
154 68
            $this->host,
155 68
            $this->port,
156 68
            $this->password,
157 68
            $this->charset,
158 68
            $this->gtid,
159 68
            $this->mariaDbGtid,
160 68
            $this->slaveId,
161 68
            $this->binLogFileName,
162 68
            $this->binLogPosition,
163 68
            $this->eventsOnly,
164 68
            $this->eventsIgnore,
165 68
            $this->tablesOnly,
166 68
            $this->databasesOnly,
167 68
            $this->tableCacheSize,
168 68
            $this->custom,
169 68
            $this->heartbeatPeriod
170
        );
171
    }
172
}