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 Tar extends SimulatorExecutable implements Simulator |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Tar Executable |
||
| 26 | * |
||
| 27 | * @var \phpbu\App\Cli\Executable\Tar |
||
| 28 | */ |
||
| 29 | protected $executable; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Path to executable. |
||
| 33 | * |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | private $pathToTar; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Path to backup |
||
| 40 | * |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | private $path; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * List of paths to exclude |
||
| 47 | * --exclude |
||
| 48 | * |
||
| 49 | * @var array |
||
| 50 | */ |
||
| 51 | private $excludes; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Special compression program |
||
| 55 | * --use-compress-program |
||
| 56 | * |
||
| 57 | * @var string |
||
| 58 | */ |
||
| 59 | private $compressProgram; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Force local file resolution |
||
| 63 | * |
||
| 64 | * --force-local |
||
| 65 | * |
||
| 66 | * @var bool |
||
| 67 | */ |
||
| 68 | private $forceLocal; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Tar should ignore failed reads |
||
| 72 | * --ignore-failed-read |
||
| 73 | * |
||
| 74 | * @var bool |
||
| 75 | */ |
||
| 76 | private $ignoreFailedRead; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Remove the packed data |
||
| 80 | * |
||
| 81 | * @var bool |
||
| 82 | */ |
||
| 83 | private $removeSourceDir; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Compression to use. |
||
| 87 | * |
||
| 88 | * @var string |
||
| 89 | */ |
||
| 90 | private $compression = ''; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Throttle cpu usage. |
||
| 94 | * |
||
| 95 | * @var string |
||
| 96 | */ |
||
| 97 | private $throttle = ''; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Path where to store the archive. |
||
| 101 | * |
||
| 102 | * @var string |
||
| 103 | */ |
||
| 104 | private $pathToArchive; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Setup. |
||
| 108 | * |
||
| 109 | * @see \phpbu\App\Backup\Source |
||
| 110 | * @param array $conf |
||
| 111 | * @throws \phpbu\App\Exception |
||
| 112 | */ |
||
| 113 | 17 | public function setup(array $conf = []) |
|
| 128 | |||
| 129 | /** |
||
| 130 | * Execute the backup. |
||
| 131 | * |
||
| 132 | * @see \phpbu\App\Backup\Source |
||
| 133 | * @param \phpbu\App\Backup\Target $target |
||
| 134 | * @param \phpbu\App\Result $result |
||
| 135 | * @return \phpbu\App\Backup\Source\Status |
||
| 136 | * @throws \phpbu\App\Exception |
||
| 137 | */ |
||
| 138 | 7 | View Code Duplication | public function backup(Target $target, Result $result) : Status |
| 154 | |||
| 155 | /** |
||
| 156 | * Setup the Executable to run the 'tar' command. |
||
| 157 | * |
||
| 158 | * @param \phpbu\App\Backup\Target |
||
| 159 | * @return \phpbu\App\Cli\Executable |
||
| 160 | */ |
||
| 161 | 15 | protected function createExecutable(Target $target) : Executable |
|
| 188 | |||
| 189 | /** |
||
| 190 | * Check the source to compress. |
||
| 191 | * |
||
| 192 | * @throws \phpbu\App\Exception |
||
| 193 | */ |
||
| 194 | 7 | private function validatePath() |
|
| 200 | |||
| 201 | /** |
||
| 202 | * Create backup status. |
||
| 203 | * |
||
| 204 | * @param \phpbu\App\Backup\Target |
||
| 205 | * @return \phpbu\App\Backup\Source\Status |
||
| 206 | */ |
||
| 207 | 3 | protected function createStatus(Target $target) : Status |
|
| 217 | } |
||
| 218 |