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 Rsync extends Cli implements Simulator |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Path to rsync binary. |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | protected $pathToRsync; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Raw args |
||
| 33 | * |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | protected $args; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Remote username |
||
| 40 | * |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | protected $user; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Target host |
||
| 47 | * |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | protected $host; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Target path |
||
| 54 | * |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | protected $path; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Files to ignore, extracted from config string separated by ":" |
||
| 61 | * |
||
| 62 | * @var array |
||
| 63 | */ |
||
| 64 | protected $excludes; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Should only the created backup be synced or the complete directory |
||
| 68 | * |
||
| 69 | * @var boolean |
||
| 70 | */ |
||
| 71 | protected $isDirSync; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Remove deleted files remotely as well |
||
| 75 | * |
||
| 76 | * @var boolean |
||
| 77 | */ |
||
| 78 | protected $delete; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * (non-PHPDoc) |
||
| 82 | * |
||
| 83 | * @see \phpbu\App\Backup\Sync::setup() |
||
| 84 | * @param array $options |
||
| 85 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 86 | */ |
||
| 87 | 9 | public function setup(array $options) |
|
| 111 | |||
| 112 | /** |
||
| 113 | * (non-PHPDoc) |
||
| 114 | * |
||
| 115 | * @see \phpbu\App\Backup\Sync::sync() |
||
| 116 | * @param \phpbu\App\Backup\Target $target |
||
| 117 | * @param \phpbu\App\Result $result |
||
| 118 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 119 | */ |
||
| 120 | 2 | View Code Duplication | public function sync(Target $target, Result $result) |
| 135 | |||
| 136 | |||
| 137 | /** |
||
| 138 | * Simulate the sync execution. |
||
| 139 | * |
||
| 140 | * @param \phpbu\App\Backup\Target $target |
||
| 141 | * @param \phpbu\App\Result $result |
||
| 142 | 6 | */ |
|
| 143 | public function simulate(Target $target, Result $result) |
||
| 150 | 3 | ||
| 151 | 3 | /** |
|
| 152 | 3 | * Create the Exec to run the 'rsync' command. |
|
| 153 | 3 | * |
|
| 154 | 3 | * @param \phpbu\App\Backup\Target $target |
|
| 155 | 3 | * @return \phpbu\App\Cli\Executable |
|
| 156 | */ |
||
| 157 | 4 | public function getExecutable(Target $target) |
|
| 175 | |||
| 176 | /** |
||
| 177 | * Return sync source. |
||
| 178 | * |
||
| 179 | * @param \phpbu\App\Backup\Target |
||
| 180 | * @return string |
||
| 181 | */ |
||
| 182 | public function getSyncSource(Target $target) |
||
| 186 | } |
||
| 187 |