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 |
||
10 | class MySql extends DbDumper |
||
11 | { |
||
12 | protected $dbName; |
||
13 | protected $userName; |
||
14 | protected $password; |
||
15 | protected $host = 'localhost'; |
||
16 | protected $port = 3306; |
||
17 | protected $ssl_ca_path; |
||
18 | protected $ssl_cert_path; |
||
19 | protected $ssl_key_path; |
||
20 | protected $socket; |
||
21 | protected $dumpBinaryPath = ''; |
||
22 | protected $useExtendedInserts = true; |
||
23 | protected $useSingleTransaction = false; |
||
24 | protected $includeTables = array(); |
||
25 | protected $excludeTables = array(); |
||
26 | protected $timeout; |
||
27 | |||
28 | /** |
||
29 | * @return string |
||
30 | */ |
||
31 | public function getDbName() |
||
35 | |||
36 | /** |
||
37 | * @param string $dbName |
||
38 | * |
||
39 | * @return \Spatie\DbDumper\Databases\MySql |
||
40 | */ |
||
41 | public function setDbName($dbName) |
||
47 | |||
48 | /** |
||
49 | * @param string $userName |
||
50 | * |
||
51 | * @return \Spatie\DbDumper\Databases\MySql |
||
52 | */ |
||
53 | public function setUserName($userName) |
||
59 | |||
60 | /** |
||
61 | * @param string $password |
||
62 | * |
||
63 | * @return \Spatie\DbDumper\Databases\MySql |
||
64 | */ |
||
65 | public function setPassword($password) |
||
71 | |||
72 | /** |
||
73 | * @param string $host |
||
74 | * |
||
75 | * @return \Spatie\DbDumper\Databases\MySql |
||
76 | */ |
||
77 | public function setHost($host) |
||
83 | |||
84 | /** |
||
85 | * @param int $port |
||
86 | * |
||
87 | * @return \Spatie\DbDumper\Databases\MySql |
||
88 | */ |
||
89 | public function setPort($port) |
||
95 | |||
96 | /** |
||
97 | * @param string $options |
||
|
|||
98 | * |
||
99 | * @return \Spatie\DbDumper\Databases\MySql |
||
100 | */ |
||
101 | public function setSSLCaPath($path) |
||
107 | |||
108 | /** |
||
109 | * @param string $path |
||
110 | * |
||
111 | * @return \Spatie\DbDumper\Databases\MySql |
||
112 | */ |
||
113 | public function setSSLCertPath($path) |
||
119 | |||
120 | /** |
||
121 | * @param string $path |
||
122 | * |
||
123 | * @return \Spatie\DbDumper\Databases\MySql |
||
124 | */ |
||
125 | public function setSSLKeyPath($path) |
||
131 | |||
132 | /** |
||
133 | * @param int $socket |
||
134 | * |
||
135 | * @return \Spatie\DbDumper\Databases\MySql |
||
136 | */ |
||
137 | public function setSocket($socket) |
||
143 | |||
144 | /** |
||
145 | * @param int $timeout |
||
146 | * |
||
147 | * @return \Spatie\DbDumper\Databases\PostgreSql |
||
148 | */ |
||
149 | public function setTimeout($timeout) |
||
155 | |||
156 | /** |
||
157 | * @param string $dumpBinaryPath |
||
158 | * |
||
159 | * @return \Spatie\DbDumper\Databases\MySql |
||
160 | */ |
||
161 | public function setDumpBinaryPath($dumpBinaryPath) |
||
171 | |||
172 | /** |
||
173 | * @param string|array $includeTables |
||
174 | * |
||
175 | * @return \Spatie\DbDumper\Databases\MySql |
||
176 | */ |
||
177 | View Code Duplication | public function includeTables($includeTables) |
|
191 | |||
192 | /** |
||
193 | * @param string/array $excludeTables |
||
194 | * |
||
195 | * @return \Spatie\DbDumper\Databases\MySql |
||
196 | */ |
||
197 | View Code Duplication | public function excludeTables($excludeTables) |
|
211 | |||
212 | /** |
||
213 | * @return \Spatie\DbDumper\Databases\MySql |
||
214 | */ |
||
215 | public function useExtendedInserts() |
||
221 | |||
222 | /** |
||
223 | * @return \Spatie\DbDumper\Databases\MySql |
||
224 | */ |
||
225 | public function dontUseExtendedInserts() |
||
231 | |||
232 | /** |
||
233 | * @return \Spatie\DbDumper\Databases\MySql |
||
234 | */ |
||
235 | public function useSingleTransaction() |
||
241 | |||
242 | /** |
||
243 | * @return \Spatie\DbDumper\Databases\MySql |
||
244 | */ |
||
245 | public function dontUseSingleTransaction() |
||
251 | |||
252 | /** |
||
253 | * Dump the contents of the database to the given file. |
||
254 | * |
||
255 | * @param string $dumpFile |
||
256 | * |
||
257 | * @throws \Spatie\DbDumper\Exceptions\CannotStartDump |
||
258 | * @throws \Spatie\DbDumper\Exceptions\DumpFailed |
||
259 | */ |
||
260 | View Code Duplication | public function dumpToFile($dumpFile) |
|
280 | |||
281 | /** |
||
282 | * Get the command that should be performed to dump the database. |
||
283 | * |
||
284 | * @param string $dumpFile |
||
285 | * @param string $temporaryCredentialsFile |
||
286 | * |
||
287 | * @return string |
||
288 | */ |
||
289 | public function getDumpCommand($dumpFile, $temporaryCredentialsFile) |
||
320 | |||
321 | /** |
||
322 | * @return string |
||
323 | */ |
||
324 | public function getContentsOfCredentialsFile() |
||
343 | |||
344 | View Code Duplication | protected function guardAgainstIncompleteCredentials() |
|
352 | } |
||
353 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.