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 |
||
| 23 | class Arangodump extends SimulatorExecutable implements Simulator |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * Path to arangodump command. |
||
| 27 | * |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | private $pathToArangodump; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Endpoint to connect to |
||
| 34 | * --server.endpoint <endpoint> |
||
| 35 | * |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | private $endpoint; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Username to connect with |
||
| 42 | * --server.username <username> |
||
| 43 | * |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | private $username; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Password to authenticate with |
||
| 50 | * --server.password <password> |
||
| 51 | * |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | private $password; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * The database to backup |
||
| 58 | * --server.database <database> |
||
| 59 | * |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | private $database; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Whether the data should be dumped or not |
||
| 66 | * --dump-data |
||
| 67 | * |
||
| 68 | * @var boolean |
||
| 69 | */ |
||
| 70 | private $dumpData; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Include system collections |
||
| 74 | * --include-system-collections |
||
| 75 | * |
||
| 76 | * @var boolean |
||
| 77 | */ |
||
| 78 | private $includeSystemCollections; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Restrict the dump to these collections |
||
| 82 | * --collection |
||
| 83 | * |
||
| 84 | * @var array |
||
| 85 | */ |
||
| 86 | private $collections; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Do not ask for the username and password when connecting to the server. |
||
| 90 | * This does not control whether the server requires authentication. |
||
| 91 | * -- disable-authentication |
||
| 92 | * |
||
| 93 | * @var boolean |
||
| 94 | */ |
||
| 95 | private $disableAuthentication; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Setup. |
||
| 99 | * |
||
| 100 | * @see \phpbu\App\Backup\Source |
||
| 101 | * @param array $conf |
||
| 102 | * @throws \phpbu\App\Exception |
||
| 103 | */ |
||
| 104 | public function setup(array $conf = array()) |
||
| 115 | |||
| 116 | 5 | /** |
|
| 117 | 5 | * Get collections and data to backup. |
|
| 118 | 5 | * |
|
| 119 | 5 | * @param array $conf |
|
| 120 | 5 | */ |
|
| 121 | 5 | protected function setupSourceData(array $conf) |
|
| 127 | |||
| 128 | /** |
||
| 129 | * (non-PHPDoc) |
||
| 130 | 5 | * |
|
| 131 | * @see \phpbu\App\Backup\Source |
||
| 132 | 5 | * @param \phpbu\App\Backup\Target $target |
|
| 133 | 5 | * @param \phpbu\App\Result $result |
|
| 134 | 5 | * @return \phpbu\App\Backup\Source\Status |
|
| 135 | 5 | * @throws \phpbu\App\Exception |
|
| 136 | */ |
||
| 137 | View Code Duplication | public function backup(Target $target, Result $result) |
|
| 149 | |||
| 150 | 2 | /** |
|
| 151 | * Create the Executable to run the arangodump command. |
||
| 152 | 2 | * |
|
| 153 | 1 | * @param \phpbu\App\Backup\Target $target |
|
| 154 | * @return \phpbu\App\Cli\Executable |
||
| 155 | * @throws \phpbu\App\Exception |
||
| 156 | 1 | */ |
|
| 157 | View Code Duplication | public function getExecutable(Target $target) |
|
| 173 | 3 | ||
| 174 | 3 | /** |
|
| 175 | 3 | * Create backup status. |
|
| 176 | 3 | * |
|
| 177 | 3 | * @param \phpbu\App\Backup\Target |
|
| 178 | 3 | * @return \phpbu\App\Backup\Source\Status |
|
| 179 | 3 | */ |
|
| 180 | protected function createStatus(Target $target) |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Get the ArangoDB dump directory. |
||
| 187 | * |
||
| 188 | * @param \phpbu\App\Backup\Target $target |
||
| 189 | * @return string |
||
| 190 | 4 | */ |
|
| 191 | public function getDumpDir(Target $target) |
||
| 195 | } |
||
| 196 |