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