Completed
Push — master ( d26594...3115e1 )
by CodexShaper
02:12
created

DumperTrait   A

Complexity

Total Complexity 31

Size/Duplication

Total Lines 229
Duplicated Lines 0 %

Test Coverage

Coverage 55.42%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 75
dl 0
loc 229
ccs 46
cts 83
cp 0.5542
rs 9.92
c 4
b 0
f 0
wmc 31

27 Methods

Rating   Name   Duplication   Size   Complexity  
A getPassword() 0 3 1
A getHost() 0 3 1
A getTimeOut() 0 3 1
A getRestorePath() 0 3 1
A getSocket() 0 3 1
A getCommandBinaryPath() 0 3 1
A getPort() 0 3 1
A getUserName() 0 3 1
A getDestinationPath() 0 3 1
A setUserName() 0 5 1
A setCompressBinaryPath() 0 4 1
A setHost() 0 5 1
A setDestinationPath() 0 5 1
A setCommandBinaryPath() 0 5 1
A setTimeOut() 0 5 1
A getDbName() 0 3 1
A setRestorePath() 0 5 1
A setCompressExtension() 0 4 1
A enableDebug() 0 4 1
A setDbName() 0 4 1
A setPassword() 0 5 1
A setCompressCommand() 0 5 1
A setTables() 0 13 3
A setIgnoreTables() 0 14 3
A setSocket() 0 5 1
A useCompress() 0 8 1
A setPort() 0 5 1
1
<?php
2
3
namespace CodexShaper\Dumper\Traits;
4
5
trait DumperTrait
6
{
7
    /*@var string*/
8
    protected $dbName;
9
    /*@var string*/
10
    protected $username;
11
    /*@var string*/
12
    protected $password;
13
    /*@var string*/
14
    protected $host = 'localhost';
15
    /*@var int*/
16
    protected $port = 3306;
17
    /*@var string*/
18
    protected $socket = '';
19
    /*@var string*/
20
    protected $commandBinaryPath = '';
21
    /*@var int*/
22
    protected $timeout = 0;
23
    /*@var array*/
24
    protected $tables = [];
25
    /*@var array*/
26
    protected $ignoreTables = [];
27
    /*@var string*/
28
    protected $destinationPath = 'dump.sql';
29
    /*@var string*/
30
    protected $restorePath = 'dump.sql';
31
    /*@var bool*/
32
    protected $isCompress = false;
33
    /*@var string*/
34
    protected $compressCommand = "gzip";
35
    /*@var string*/
36
    protected $compressBinaryPath = "";
37
    /*@var string*/
38
    protected $compressExtension = ".gz";
39
    /*@var bool*/
40
    protected $debug = false;
41
    /*@var string*/
42
    protected $command = "";
43
44 112
    public function setDbName(string $name)
45
    {
46 112
        $this->dbName = $name;
47 112
        return $this;
48
    }
49
50 72
    public function setUserName(string $username)
51
    {
52 72
        $this->username = $username;
53
54 72
        return $this;
55
    }
56
57 72
    public function setPassword(string $password)
58
    {
59 72
        $this->password = $password;
60
61 72
        return $this;
62
    }
63
64 4
    public function setHost(string $host)
65
    {
66 4
        $this->host = $host;
67
68 4
        return $this;
69
    }
70
71 6
    public function setPort(int $port)
72
    {
73 6
        $this->port = $port;
74
75 6
        return $this;
76
    }
77
78 4
    public function setSocket(string $socket)
79
    {
80 4
        $this->socket = $socket;
81
82 4
        return $this;
83
    }
84
85
    public function setTimeOut(int $timeout)
86
    {
87
        $this->timeout = $timeout;
88
89
        return $this;
90
    }
91
    /**
92
     * @param string|array $tables
93
     * @throws \Exception
94
     */
95 12
    public function setTables($tables)
96
    {
97 12
        if (!empty($this->ignoreTables)) {
98
            throw new \Exception("You can choose only once between tables and ignoreTables at a time");
99
        }
100
101 12
        if (is_string($tables)) {
102 4
            $tables = [$tables];
103
        }
104
105 12
        $this->tables = $tables;
106
107 12
        return $this;
108
    }
109
    /**
110
     * @param string|array $tables
111
     * @throws \Exception
112
     */
113 12
    public function setIgnoreTables($tables)
114
    {
115 12
        if (!empty($this->tables)) {
116 4
            throw new \Exception("You can choose only once between tables and ignoreTables at a time");
117
118
        }
119
120 8
        if (is_string($tables)) {
121 4
            $tables = [$tables];
122
        }
123
124 8
        $this->ignoreTables = $tables;
125
126 8
        return $this;
127
    }
128
129 12
    public function setCommandBinaryPath(string $path)
130
    {
131 12
        $this->commandBinaryPath = $path;
132
133 12
        return $this;
134
    }
135
136 76
    public function setDestinationPath(string $path)
137
    {
138 76
        $this->destinationPath = $path;
139
140 76
        return $this;
141
    }
142
143 32
    public function setRestorePath(string $path)
144
    {
145 32
        $this->restorePath = $path;
146
147 32
        return $this;
148
    }
149
150
    // Compress
151
    public function setCompressBinaryPath(string $path)
152
    {
153
        $this->compressBinaryPath = $path;
154
        return $this;
155
    }
156
157
    public function setCompressCommand(string $command)
158
    {
159
        $this->compressCommand = $command;
160
        $this->isCompress      = true;
161
        return $this;
162
    }
163
164
    public function setCompressExtension(string $extension)
165
    {
166
        $this->compressExtension = $extension;
167
        return $this;
168
    }
169
170 16
    public function useCompress(string $command = "gzip", string $extension = ".gz", string $binary_path = "")
171
    {
172 16
        $this->compressCommand    = $command;
173 16
        $this->compressExtension  = $extension;
174 16
        $this->compressBinaryPath = $binary_path;
175 16
        $this->isCompress         = true;
176
177 16
        return $this;
178
    }
179
180
    public function enableDebug()
181
    {
182
        $this->debug = true;
183
        return $this;
184
    }
185
186
    public function getDbName()
187
    {
188
        return $this->dbName;
189
    }
190
191
    public function getUserName()
192
    {
193
        return $this->username;
194
    }
195
196
    public function getPassword()
197
    {
198
        return $this->password;
199
    }
200
201
    public function getHost()
202
    {
203
        return $this->host;
204
    }
205
206
    public function getPort()
207
    {
208
        return $this->port;
209
    }
210
211
    public function getSocket()
212
    {
213
        return $this->socket;
214
    }
215
216
    public function getTimeOut()
217
    {
218
        return $this->timeout;
219
    }
220
221
    public function getCommandBinaryPath()
222
    {
223
        return $this->commandBinaryPath;
224
    }
225
226
    public function getDestinationPath()
227
    {
228
        return $this->destinationPath;
229
    }
230
231
    public function getRestorePath()
232
    {
233
        return $this->restorePath;
234
    }
235
}
236