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 Tar extends SimulatorExecutable implements Simulator |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * Tar Executable |
||
| 27 | * |
||
| 28 | * @var \phpbu\App\Cli\Executable\Tar |
||
| 29 | */ |
||
| 30 | protected $executable; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Path to executable. |
||
| 34 | * |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | private $pathToTar; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Path to backup |
||
| 41 | * |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | private $path; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * List of paths to exclude |
||
| 48 | * --exclude |
||
| 49 | * |
||
| 50 | * @var array |
||
| 51 | */ |
||
| 52 | private $excludes; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Special compression program |
||
| 56 | * --use-compress-program |
||
| 57 | * |
||
| 58 | * @var string |
||
| 59 | */ |
||
| 60 | private $compressProgram; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Force local file resolution |
||
| 64 | * |
||
| 65 | * --force-local |
||
| 66 | * |
||
| 67 | * @var bool |
||
| 68 | */ |
||
| 69 | private $forceLocal; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Tar should ignore failed reads |
||
| 73 | * --ignore-failed-read |
||
| 74 | * |
||
| 75 | * @var bool |
||
| 76 | */ |
||
| 77 | private $ignoreFailedRead; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Remove the packed data |
||
| 81 | * |
||
| 82 | * @var bool |
||
| 83 | */ |
||
| 84 | private $removeSourceDir; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Compression to use. |
||
| 88 | * |
||
| 89 | * @var string |
||
| 90 | */ |
||
| 91 | private $compression = ''; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Throttle cpu usage. |
||
| 95 | * |
||
| 96 | * @var string |
||
| 97 | */ |
||
| 98 | private $throttle = ''; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Path where to store the archive. |
||
| 102 | * |
||
| 103 | * @var string |
||
| 104 | */ |
||
| 105 | private $pathToArchive; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Setup. |
||
| 109 | * |
||
| 110 | * @see \phpbu\App\Backup\Source |
||
| 111 | * @param array $conf |
||
| 112 | * @throws \phpbu\App\Exception |
||
| 113 | */ |
||
| 114 | 17 | public function setup(array $conf = []) |
|
| 125 | |||
| 126 | /** |
||
| 127 | * Setup the path to the directory that should be compressed. |
||
| 128 | * |
||
| 129 | * @param array $conf |
||
| 130 | * @throws \phpbu\App\Exception |
||
| 131 | */ |
||
| 132 | 17 | protected function setupPath(array $conf) |
|
| 143 | |||
| 144 | /** |
||
| 145 | * Execute the backup. |
||
| 146 | * |
||
| 147 | * @see \phpbu\App\Backup\Source |
||
| 148 | * @param \phpbu\App\Backup\Target $target |
||
| 149 | * @param \phpbu\App\Result $result |
||
| 150 | * @return \phpbu\App\Backup\Source\Status |
||
| 151 | * @throws \phpbu\App\Exception |
||
| 152 | */ |
||
| 153 | 7 | View Code Duplication | public function backup(Target $target, Result $result) : Status |
| 169 | |||
| 170 | /** |
||
| 171 | * Setup the Executable to run the 'tar' command. |
||
| 172 | * |
||
| 173 | * @param \phpbu\App\Backup\Target |
||
| 174 | * @return \phpbu\App\Cli\Executable |
||
| 175 | */ |
||
| 176 | 15 | protected function createExecutable(Target $target) : Executable |
|
| 203 | |||
| 204 | /** |
||
| 205 | * Check the source to compress. |
||
| 206 | * |
||
| 207 | * @throws \phpbu\App\Exception |
||
| 208 | */ |
||
| 209 | 7 | private function validatePath() |
|
| 215 | |||
| 216 | /** |
||
| 217 | * Create backup status. |
||
| 218 | * |
||
| 219 | * @param \phpbu\App\Backup\Target |
||
| 220 | * @return \phpbu\App\Backup\Source\Status |
||
| 221 | */ |
||
| 222 | 3 | protected function createStatus(Target $target) : Status |
|
| 232 | } |
||
| 233 |