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 |
||
| 22 | class Mongodump extends SimulatorExecutable implements Simulator |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Path to mongodump command. |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | private $pathToMongodump; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Use IPv6 |
||
| 33 | * --ipv6 |
||
| 34 | * |
||
| 35 | * @var boolean |
||
| 36 | */ |
||
| 37 | private $useIPv6; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Host to connect to |
||
| 41 | * --host <hostname:port> |
||
| 42 | * |
||
| 43 | * @var string |
||
| 44 | */ |
||
| 45 | private $host; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * User to connect with |
||
| 49 | * --user <username> |
||
| 50 | * |
||
| 51 | * @var string |
||
| 52 | */ |
||
| 53 | private $user; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Password to authenticate with |
||
| 57 | * --password <password> |
||
| 58 | * |
||
| 59 | * @var string |
||
| 60 | */ |
||
| 61 | private $password; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Database to use for authentication |
||
| 65 | * --authenticationDatabase <dbname> |
||
| 66 | * |
||
| 67 | * @var string |
||
| 68 | */ |
||
| 69 | private $authenticationDatabase; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * List of databases to backup |
||
| 73 | * --db <database> |
||
| 74 | * |
||
| 75 | * @var array |
||
| 76 | */ |
||
| 77 | private $databases; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * List of collections to backup |
||
| 81 | * --collection <collection> |
||
| 82 | * |
||
| 83 | * @var array |
||
| 84 | */ |
||
| 85 | private $collections; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * List of collections to ignore |
||
| 89 | * --excludeCollections array of strings |
||
| 90 | * |
||
| 91 | * @var array |
||
| 92 | */ |
||
| 93 | private $excludeCollections; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * List of prefixes to exclude collections |
||
| 97 | * --excludeCollectionWithPrefix array of strings |
||
| 98 | * |
||
| 99 | * @var array |
||
| 100 | */ |
||
| 101 | private $excludeCollectionsWithPrefix; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * (No PHPDoc) |
||
| 105 | * |
||
| 106 | * @see \phpbu\App\Backup\Source |
||
| 107 | * @param array $conf |
||
| 108 | * @throws \phpbu\App\Exception |
||
| 109 | */ |
||
| 110 | public function setup(array $conf = []) |
||
| 119 | |||
| 120 | 3 | /** |
|
| 121 | 3 | * Fetch databases and collections to backup. |
|
| 122 | * |
||
| 123 | * @param array $conf |
||
| 124 | 3 | */ |
|
| 125 | 3 | View Code Duplication | protected function setupSourceData(array $conf) |
| 132 | |||
| 133 | /** |
||
| 134 | 3 | * Fetch credential settings. |
|
| 135 | * |
||
| 136 | 3 | * @param array $conf |
|
| 137 | 3 | */ |
|
| 138 | 3 | protected function setupCredentials(array $conf) |
|
| 145 | |||
| 146 | /** |
||
| 147 | 3 | * (non-PHPDoc) |
|
| 148 | * |
||
| 149 | 3 | * @see \phpbu\App\Backup\Source |
|
| 150 | 3 | * @param \phpbu\App\Backup\Target $target |
|
| 151 | 3 | * @param \phpbu\App\Result $result |
|
| 152 | 3 | * @return \phpbu\App\Backup\Source\Status |
|
| 153 | 3 | * @throws \phpbu\App\Exception |
|
| 154 | */ |
||
| 155 | View Code Duplication | public function backup(Target $target, Result $result) |
|
| 168 | |||
| 169 | 2 | /** |
|
| 170 | * Create the Executable to run the Mongodump command. |
||
| 171 | 2 | * |
|
| 172 | 1 | * @param \phpbu\App\Backup\Target $target |
|
| 173 | * @return \phpbu\App\Cli\Executable |
||
| 174 | */ |
||
| 175 | 1 | View Code Duplication | public function getExecutable(Target $target) |
| 191 | 1 | ||
| 192 | 1 | /** |
|
| 193 | 1 | * Create backup status. |
|
| 194 | 1 | * |
|
| 195 | 1 | * @param \phpbu\App\Backup\Target |
|
| 196 | 1 | * @return \phpbu\App\Backup\Source\Status |
|
| 197 | 1 | */ |
|
| 198 | protected function createStatus(Target $target) |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Get the MongoDB dump directory. |
||
| 205 | * |
||
| 206 | * @param \phpbu\App\Backup\Target $target |
||
| 207 | * @return string |
||
| 208 | 2 | */ |
|
| 209 | public function getDumpDir(Target $target) |
||
| 213 | } |
||
| 214 |