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 | * The compressor cmd |
||
| 94 | * |
||
| 95 | * @var boolean |
||
| 96 | */ |
||
| 97 | private $compressor; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Use mysqldump quick mode |
||
| 101 | * -q |
||
| 102 | * |
||
| 103 | * @var boolean |
||
| 104 | */ |
||
| 105 | private $quick; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * |
||
| 109 | * Lock tables option |
||
| 110 | * --lock-tables |
||
| 111 | * |
||
| 112 | * @var bool |
||
| 113 | */ |
||
| 114 | private $lockTables; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Use mysqldump with compression |
||
| 118 | * -C |
||
| 119 | * |
||
| 120 | * @var boolean |
||
| 121 | */ |
||
| 122 | private $compress; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Use mysqldump with extended insert |
||
| 126 | * -e |
||
| 127 | * |
||
| 128 | * @var boolean |
||
| 129 | */ |
||
| 130 | private $extendedInsert; |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Dump blob fields as hex. |
||
| 134 | * --hex-blob |
||
| 135 | * |
||
| 136 | * @var boolean |
||
| 137 | */ |
||
| 138 | private $hexBlob; |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Dump only table structures |
||
| 142 | * --no-data |
||
| 143 | * |
||
| 144 | * @var boolean |
||
| 145 | */ |
||
| 146 | 5 | private $noData; |
|
| 147 | |||
| 148 | 5 | /** |
|
| 149 | * Setup. |
||
| 150 | 5 | * |
|
| 151 | 5 | * @see \phpbu\App\Backup\Source |
|
| 152 | 5 | * @param array $conf |
|
| 153 | 5 | * @throws \phpbu\App\Exception |
|
| 154 | 5 | */ |
|
| 155 | 5 | public function setup(array $conf = []) |
|
| 177 | |||
| 178 | /** |
||
| 179 | * Get tables and databases to backup. |
||
| 180 | * |
||
| 181 | * @param array $conf |
||
| 182 | */ |
||
| 183 | View Code Duplication | protected function setupSourceData(array $conf) |
|
| 190 | 2 | ||
| 191 | /** |
||
| 192 | 2 | * Execute the backup. |
|
| 193 | 1 | * |
|
| 194 | * @see \phpbu\App\Backup\Source |
||
| 195 | * @param \phpbu\App\Backup\Target $target |
||
| 196 | 1 | * @param \phpbu\App\Result $result |
|
| 197 | * @return \phpbu\App\Backup\Source\Status |
||
| 198 | * @throws \phpbu\App\Exception |
||
| 199 | */ |
||
| 200 | public function backup(Target $target, Result $result) |
||
| 219 | 3 | ||
| 220 | 3 | /** |
|
| 221 | 3 | * Create the Executable to run the mysqldump command. |
|
| 222 | 3 | * |
|
| 223 | 5 | * @param \phpbu\App\Backup\Target $target |
|
| 224 | * @return \phpbu\App\Cli\Executable |
||
| 225 | */ |
||
| 226 | public function getExecutable(Target $target) |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Create backup status. |
||
| 254 | * |
||
| 255 | * @param \phpbu\App\Backup\Target |
||
| 256 | * @return \phpbu\App\Backup\Source\Status |
||
| 257 | */ |
||
| 258 | protected function createStatus(Target $target) |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Return dump target path. |
||
| 267 | * |
||
| 268 | * @param \phpbu\App\Backup\Target $target |
||
| 269 | * @return string |
||
| 270 | */ |
||
| 271 | private function getDumpTarget(Target $target) |
||
| 275 | } |
||
| 276 |