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 |
||
| 20 | class Runner |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * phpbu Factory |
||
| 24 | * |
||
| 25 | * @var \phpbu\App\Factory |
||
| 26 | */ |
||
| 27 | protected $factory; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Application result |
||
| 31 | * |
||
| 32 | * @var \phpbu\App\Result |
||
| 33 | */ |
||
| 34 | protected $result; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Backup failed |
||
| 38 | * |
||
| 39 | * @var boolean |
||
| 40 | */ |
||
| 41 | protected $failure; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Constructor |
||
| 45 | * |
||
| 46 | * @param \phpbu\App\Factory $factory |
||
| 47 | */ |
||
| 48 | public function __construct(Factory $factory) |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Run phpbu |
||
| 55 | * |
||
| 56 | * @param \phpbu\App\Configuration $configuration |
||
| 57 | * @param \phpbu\App\Factory |
||
| 58 | * @return \phpbu\App\Result |
||
| 59 | */ |
||
| 60 | public function run(Configuration $configuration) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * This executes a bootstrap runner to handle ini settings and the bootstrap file inclusion. |
||
| 135 | * |
||
| 136 | * @param \phpbu\App\Configuration $configuration |
||
| 137 | * @throws \phpbu\App\Exception |
||
| 138 | */ |
||
| 139 | protected function setupEnvironment(Configuration $configuration) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Create and register all configured loggers. |
||
| 147 | * |
||
| 148 | * @param \phpbu\App\Configuration $configuration |
||
| 149 | */ |
||
| 150 | protected function setupLoggers(Configuration $configuration) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Create a target. |
||
| 168 | * |
||
| 169 | * @param \phpbu\App\Configuration\Backup\Target $conf |
||
| 170 | * @return \phpbu\App\Backup\Target |
||
| 171 | * @throws \phpbu\App\Exception |
||
| 172 | */ |
||
| 173 | protected function createTarget(Configuration\Backup\Target $conf) |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Execute the backup. |
||
| 187 | * |
||
| 188 | * @param \phpbu\App\Configuration\Backup $conf |
||
| 189 | * @param \phpbu\App\Backup\Target $target |
||
| 190 | * @throws \Exception |
||
| 191 | */ |
||
| 192 | protected function executeSource(Configuration\Backup $conf, Target $target) |
||
| 193 | { |
||
| 194 | $this->result->backupStart($conf); |
||
| 195 | $source = $this->factory->createSource($conf->getSource()->type, $conf->getSource()->options); |
||
| 196 | $runner = $this->factory->createRunner('source'); |
||
| 197 | $runner->run($source, $target, $this->result); |
||
| 198 | $this->result->backupEnd($conf); |
||
| 199 | } |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Execute checks. |
||
| 203 | * |
||
| 204 | * @param \phpbu\App\Configuration\Backup $backup |
||
| 205 | * @param \phpbu\App\Backup\Target $target |
||
| 206 | * @param \phpbu\App\Backup\Collector $collector |
||
| 207 | * @throws \Exception |
||
| 208 | */ |
||
| 209 | protected function executeChecks(Configuration\Backup $backup, Target $target, Collector $collector) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Execute encryption. |
||
| 222 | * |
||
| 223 | * @param \phpbu\App\Configuration\Backup $backup |
||
| 224 | * @param \phpbu\App\Backup\Target $target |
||
| 225 | */ |
||
| 226 | View Code Duplication | protected function executeCrypt(Configuration\Backup $backup, Target $target) |
|
| 246 | |||
| 247 | /** |
||
| 248 | * Execute the syncs. |
||
| 249 | * |
||
| 250 | * @param \phpbu\App\Configuration\Backup $backup |
||
| 251 | * @param \phpbu\App\Backup\Target $target |
||
| 252 | * @throws \Exception |
||
| 253 | */ |
||
| 254 | protected function executeSyncs(Configuration\Backup $backup, Target $target) |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Execute the cleanup. |
||
| 277 | * |
||
| 278 | * @param \phpbu\App\Configuration\Backup $backup |
||
| 279 | * @param \phpbu\App\Backup\Target $target |
||
| 280 | * @param \phpbu\App\Backup\Collector $collector |
||
| 281 | * @throws \Exception |
||
| 282 | */ |
||
| 283 | View Code Duplication | protected function executeCleanup(Configuration\Backup $backup, Target $target, Collector $collector) |
|
| 303 | } |
||
| 304 |