Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
21 | class Mysqldump extends SimulatorExecutable implements Simulator |
||
22 | { |
||
23 | /** |
||
24 | * Path to executable. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | private $pathToMysqldump; |
||
29 | |||
30 | /** |
||
31 | * Host to connect to |
||
32 | * --host <hostname> |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | private $host; |
||
37 | |||
38 | /** |
||
39 | * User to connect with |
||
40 | * --user <username> |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | private $user; |
||
45 | |||
46 | /** |
||
47 | * Password to authenticate with |
||
48 | * --password <password> |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | private $password; |
||
53 | |||
54 | /** |
||
55 | * List of tables to backup |
||
56 | * --tables array of strings |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | private $tables; |
||
61 | |||
62 | /** |
||
63 | * List of databases to backup |
||
64 | * --databases array of strings |
||
65 | * |
||
66 | * @var array |
||
67 | */ |
||
68 | private $databases; |
||
69 | |||
70 | /** |
||
71 | * List of tables to ignore |
||
72 | * |
||
73 | * @var array |
||
74 | */ |
||
75 | private $ignoreTables; |
||
76 | |||
77 | /** |
||
78 | * List of tables where only the table structure is stored |
||
79 | * |
||
80 | * @var array |
||
81 | */ |
||
82 | private $structureOnly; |
||
83 | |||
84 | /** |
||
85 | * Table separated data files |
||
86 | * --tab |
||
87 | * |
||
88 | * @var boolean |
||
89 | */ |
||
90 | private $filePerTable; |
||
91 | |||
92 | /** |
||
93 | * Use mysqldump quick mode |
||
94 | * -q |
||
95 | * |
||
96 | * @var boolean |
||
97 | */ |
||
98 | private $quick; |
||
99 | |||
100 | /** |
||
101 | * |
||
102 | * Lock tables option |
||
103 | * --lock-tables |
||
104 | * |
||
105 | * @var bool |
||
106 | */ |
||
107 | private $lockTables; |
||
108 | |||
109 | /** |
||
110 | * Use mysqldump with compression |
||
111 | * -C |
||
112 | * |
||
113 | * @var boolean |
||
114 | */ |
||
115 | private $compress; |
||
116 | |||
117 | /** |
||
118 | * Use mysqldump with extended insert |
||
119 | * -e |
||
120 | * |
||
121 | * @var boolean |
||
122 | */ |
||
123 | private $extendedInsert; |
||
124 | |||
125 | /** |
||
126 | * Dump blob fields as hex. |
||
127 | * --hex-blob |
||
128 | * |
||
129 | * @var boolean |
||
130 | */ |
||
131 | private $hexBlob; |
||
132 | |||
133 | /** |
||
134 | * Dump only table structures |
||
135 | * --no-data |
||
136 | * |
||
137 | * @var boolean |
||
138 | */ |
||
139 | private $noData; |
||
140 | |||
141 | /** |
||
142 | * Setup. |
||
143 | * |
||
144 | * @see \phpbu\App\Backup\Source |
||
145 | * @param array $conf |
||
146 | 5 | * @throws \phpbu\App\Exception |
|
147 | */ |
||
148 | 5 | public function setup(array $conf = []) |
|
169 | 5 | ||
170 | 5 | /** |
|
171 | 5 | * Get tables and databases to backup. |
|
172 | 5 | * |
|
173 | 5 | * @param array $conf |
|
174 | */ |
||
175 | View Code Duplication | protected function setupSourceData(array $conf) |
|
182 | |||
183 | /** |
||
184 | 2 | * Execute the backup. |
|
185 | * |
||
186 | * @see \phpbu\App\Backup\Source |
||
187 | 2 | * @param \phpbu\App\Backup\Target $target |
|
188 | 2 | * @param \phpbu\App\Result $result |
|
189 | * @return \phpbu\App\Backup\Source\Status |
||
190 | 2 | * @throws \phpbu\App\Exception |
|
191 | */ |
||
192 | 2 | public function backup(Target $target, Result $result) |
|
211 | 3 | ||
212 | 3 | /** |
|
213 | 3 | * Create the Executable to run the mysqldump command. |
|
214 | 3 | * |
|
215 | 3 | * @param \phpbu\App\Backup\Target $target |
|
216 | 3 | * @return \phpbu\App\Cli\Executable |
|
217 | 3 | */ |
|
218 | 3 | public function getExecutable(Target $target) |
|
239 | |||
240 | /** |
||
241 | * Create backup status. |
||
242 | * |
||
243 | * @param \phpbu\App\Backup\Target |
||
244 | * @return \phpbu\App\Backup\Source\Status |
||
245 | */ |
||
246 | protected function createStatus(Target $target) |
||
252 | |||
253 | /** |
||
254 | * Return dump target path. |
||
255 | * |
||
256 | * @param \phpbu\App\Backup\Target $target |
||
257 | * @return string |
||
258 | */ |
||
259 | private function getDumpTarget(Target $target) |
||
263 | } |
||
264 |