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 | abstract class Xtp implements Simulator |
||
23 | { |
||
24 | /** |
||
25 | * Host to connect to |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $host; |
||
30 | |||
31 | /** |
||
32 | * User to connect with |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $user; |
||
37 | |||
38 | /** |
||
39 | * Password to authenticate user |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $password; |
||
44 | |||
45 | /** |
||
46 | * Remote path where to put the backup |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | protected $remotePath; |
||
51 | |||
52 | /** |
||
53 | * Check for loaded libraries or extensions. |
||
54 | * |
||
55 | * @throws \phpbu\App\Backup\Sync\Exception |
||
56 | */ |
||
57 | abstract protected function checkRequirements(); |
||
58 | |||
59 | /** |
||
60 | * Return implemented (*)TP protocol name. |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | abstract protected function getProtocolName(); |
||
65 | |||
66 | /** |
||
67 | * (non-PHPDoc) |
||
68 | * |
||
69 | * @see \phpbu\App\Backup\Sync::setup() |
||
70 | * @param array $config |
||
71 | * @throws \phpbu\App\Backup\Sync\Exception |
||
72 | */ |
||
73 | public function setup(array $config) |
||
94 | |||
95 | /** |
||
96 | * Simulate the sync execution. |
||
97 | * |
||
98 | * @param \phpbu\App\Backup\Target $target |
||
99 | * @param \phpbu\App\Result $result |
||
100 | */ |
||
101 | View Code Duplication | public function simulate(Target $target, Result $result) |
|
111 | } |
||
112 |
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.