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 | * Instead of archiving symbolic links, archive the files they link to |
||
| 109 | * |
||
| 110 | * @var bool |
||
| 111 | */ |
||
| 112 | private $dereference; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Setup. |
||
| 116 | * |
||
| 117 | * @see \phpbu\App\Backup\Source |
||
| 118 | * @param array $conf |
||
| 119 | * @throws \phpbu\App\Exception |
||
| 120 | */ |
||
| 121 | 18 | public function setup(array $conf = []) |
|
| 133 | |||
| 134 | /** |
||
| 135 | * Setup the path to the directory that should be compressed. |
||
| 136 | * |
||
| 137 | * @param array $conf |
||
| 138 | * @throws \phpbu\App\Exception |
||
| 139 | */ |
||
| 140 | 18 | protected function setupPath(array $conf) |
|
| 151 | |||
| 152 | /** |
||
| 153 | * Execute the backup. |
||
| 154 | * |
||
| 155 | * @see \phpbu\App\Backup\Source |
||
| 156 | * @param \phpbu\App\Backup\Target $target |
||
| 157 | * @param \phpbu\App\Result $result |
||
| 158 | * @return \phpbu\App\Backup\Source\Status |
||
| 159 | * @throws \phpbu\App\Exception |
||
| 160 | */ |
||
| 161 | 7 | View Code Duplication | public function backup(Target $target, Result $result) : Status |
| 177 | |||
| 178 | /** |
||
| 179 | * Setup the Executable to run the 'tar' command. |
||
| 180 | * |
||
| 181 | * @param \phpbu\App\Backup\Target $target |
||
| 182 | * @return \phpbu\App\Cli\Executable |
||
| 183 | */ |
||
| 184 | 16 | protected function createExecutable(Target $target) : Executable |
|
| 212 | |||
| 213 | /** |
||
| 214 | * Check the source to compress. |
||
| 215 | * |
||
| 216 | * @throws \phpbu\App\Exception |
||
| 217 | */ |
||
| 218 | 7 | private function validatePath() |
|
| 224 | |||
| 225 | /** |
||
| 226 | * Create backup status. |
||
| 227 | * |
||
| 228 | * @param \phpbu\App\Backup\Target $target |
||
| 229 | * @return \phpbu\App\Backup\Source\Status |
||
| 230 | */ |
||
| 231 | 3 | protected function createStatus(Target $target) : Status |
|
| 241 | } |
||
| 242 |