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 Elasticdump extends SimulatorExecutable implements Simulator |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * Path to elasticdump binary. |
||
| 27 | * |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | private $pathToElasticdump; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Host to connect to |
||
| 34 | * |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | private $host; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * User to connect with |
||
| 41 | * |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | private $user; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Password to authenticate with |
||
| 48 | * |
||
| 49 | * @var string |
||
| 50 | */ |
||
| 51 | private $password; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Specific index to backup |
||
| 55 | * |
||
| 56 | * @var string |
||
| 57 | */ |
||
| 58 | private $index; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Whether to backup the mapping or data |
||
| 62 | * --type |
||
| 63 | * |
||
| 64 | * @var string |
||
| 65 | */ |
||
| 66 | private $type; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Setup. |
||
| 70 | * |
||
| 71 | * @see \phpbu\App\Backup\Source |
||
| 72 | * @param array $conf |
||
| 73 | * @throws \phpbu\App\Exception |
||
| 74 | */ |
||
| 75 | View Code Duplication | public function setup(array $conf = array()) |
|
| 86 | |||
| 87 | /** |
||
| 88 | 5 | * Get index and type. |
|
| 89 | * |
||
| 90 | 5 | * @param array $conf |
|
| 91 | 5 | */ |
|
| 92 | 5 | protected function setupSourceData(array $conf) |
|
| 97 | |||
| 98 | /** |
||
| 99 | * (non-PHPDoc) |
||
| 100 | * |
||
| 101 | 5 | * @see \phpbu\App\Backup\Source |
|
| 102 | * @param \phpbu\App\Backup\Target $target |
||
| 103 | 5 | * @param \phpbu\App\Result $result |
|
| 104 | 5 | * @return \phpbu\App\Backup\Source\Status |
|
| 105 | 5 | * @throws \phpbu\App\Exception |
|
| 106 | */ |
||
| 107 | View Code Duplication | public function backup(Target $target, Result $result) |
|
| 119 | |||
| 120 | 2 | /** |
|
| 121 | * Create the Executable to run the elasticdump command. |
||
| 122 | 2 | * |
|
| 123 | 1 | * @param \phpbu\App\Backup\Target $target |
|
| 124 | * @return \phpbu\App\Cli\Executable |
||
| 125 | * @throws \phpbu\App\Exception |
||
| 126 | 1 | */ |
|
| 127 | View Code Duplication | public function getExecutable(Target $target) |
|
| 139 | 3 | ||
| 140 | 3 | /** |
|
| 141 | 3 | * Create backup status. |
|
| 142 | 3 | * |
|
| 143 | 3 | * @param \phpbu\App\Backup\Target $target |
|
| 144 | 3 | * @return \phpbu\App\Backup\Source\Status |
|
| 145 | 3 | */ |
|
| 146 | 3 | protected function createStatus(Target $target) |
|
| 150 | } |
||
| 151 |