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 Rsync extends Cli implements Simulator |
||
24 | { |
||
25 | use RsyncTrait; |
||
26 | |||
27 | /** |
||
28 | * Setup the rsync sync. |
||
29 | * |
||
30 | * @see \phpbu\App\Backup\Sync::setup() |
||
31 | * @param array $options |
||
32 | * @throws \phpbu\App\Backup\Sync\Exception |
||
33 | */ |
||
34 | 13 | public function setup(array $options) |
|
42 | |||
43 | /** |
||
44 | * Execute the sync. |
||
45 | * |
||
46 | * @see \phpbu\App\Backup\Sync::sync() |
||
47 | * @param \phpbu\App\Backup\Target $target |
||
48 | * @param \phpbu\App\Result $result |
||
49 | * @throws \phpbu\App\Backup\Sync\Exception |
||
50 | */ |
||
51 | 2 | View Code Duplication | public function sync(Target $target, Result $result) |
66 | |||
67 | /** |
||
68 | * Simulate the sync execution. |
||
69 | * |
||
70 | * @param \phpbu\App\Backup\Target $target |
||
71 | * @param \phpbu\App\Result $result |
||
72 | */ |
||
73 | 1 | public function simulate(Target $target, Result $result) |
|
80 | |||
81 | /** |
||
82 | * Setup the Executable to run the 'rsync' command. |
||
83 | * |
||
84 | * @param \phpbu\App\Backup\Target |
||
85 | * @return \phpbu\App\Cli\Executable |
||
86 | */ |
||
87 | 9 | protected function createExecutable(Target $target) : Executable |
|
110 | |||
111 | /** |
||
112 | * Execute the remote clean up if needed |
||
113 | * |
||
114 | * @param \phpbu\App\Backup\Target $target |
||
115 | * @param \phpbu\App\Result $result |
||
116 | */ |
||
117 | public function cleanup(Target $target, Result $result) |
||
121 | } |
||
122 |