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 | 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 | 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 | public function simulate(Target $target, Result $result) |
||
80 | |||
81 | /** |
||
82 | * Configure the Executable to run the 'rsync' command. |
||
83 | * |
||
84 | * @param \phpbu\App\Cli\Executable\Rsync $exec |
||
85 | * @param \phpbu\App\Backup\Target $target |
||
86 | */ |
||
87 | 9 | View Code Duplication | protected function configureExecutable(Executable\Rsync $exec, Target $target) |
97 | } |
||
98 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.