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 |
||
19 | class Ftp extends Xtp implements Simulator |
||
20 | { |
||
21 | use Clearable; |
||
22 | |||
23 | /** |
||
24 | * FTP connection stream |
||
25 | * |
||
26 | * @var resource |
||
27 | */ |
||
28 | protected $ftpConnection; |
||
29 | |||
30 | /** |
||
31 | * Determine should ftp connects via passive mode. |
||
32 | * |
||
33 | * @var bool |
||
34 | */ |
||
35 | protected $passive; |
||
36 | |||
37 | /** |
||
38 | * Setup the Ftp sync. |
||
39 | * |
||
40 | * @param array $config |
||
41 | * @throws \phpbu\App\Backup\Sync\Exception |
||
42 | * @throws \phpbu\App\Exception |
||
43 | */ |
||
44 | 6 | public function setup(array $config) |
|
55 | |||
56 | /** |
||
57 | * Check for required loaded libraries or extensions. |
||
58 | * |
||
59 | * @throws \phpbu\App\Backup\Sync\Exception |
||
60 | */ |
||
61 | 5 | protected function checkRequirements() |
|
67 | |||
68 | /** |
||
69 | * Return implemented (*)TP protocol name. |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | 1 | protected function getProtocolName() |
|
77 | |||
78 | /** |
||
79 | * (non-PHPDoc) |
||
80 | * |
||
81 | * @see \phpbu\App\Backup\Sync::sync() |
||
82 | * @param \phpbu\App\Backup\Target $target |
||
83 | * @param \phpbu\App\Result $result |
||
84 | * @throws \phpbu\App\Backup\Sync\Exception |
||
85 | */ |
||
86 | public function sync(Target $target, Result $result) |
||
141 | |||
142 | /** |
||
143 | * Execute the remote clean up if needed |
||
144 | * |
||
145 | * @param \phpbu\App\Backup\Target $target |
||
146 | * @param \phpbu\App\Result $result |
||
147 | */ |
||
148 | public function cleanup(Target $target, Result $result) |
||
157 | } |
||
158 |