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 |
||
21 | class Sftp extends Xtp implements Simulator |
||
22 | { |
||
23 | /** |
||
24 | * @var phpseclib\Net\SFTP |
||
25 | */ |
||
26 | protected $sftp; |
||
27 | |||
28 | /** |
||
29 | * (non-PHPDoc) |
||
30 | * |
||
31 | * @see \phpbu\App\Backup\Sync::setup() |
||
32 | * @param array $config |
||
33 | * @throws \phpbu\App\Backup\Sync\Exception |
||
34 | * @throws \phpbu\App\Exception |
||
35 | */ |
||
36 | 7 | public function setup(array $config) |
|
42 | |||
43 | /** |
||
44 | * Check for required loaded libraries or extensions. |
||
45 | * |
||
46 | * @throws \phpbu\App\Backup\Sync\Exception |
||
47 | */ |
||
48 | 7 | protected function checkRequirements() |
|
54 | |||
55 | /** |
||
56 | * Return implemented (*)TP protocol name. |
||
57 | * |
||
58 | * @return string |
||
59 | */ |
||
60 | 1 | protected function getProtocolName() |
|
64 | |||
65 | /** |
||
66 | * (non-PHPDoc) |
||
67 | * |
||
68 | * @see \phpbu\App\Backup\Sync::sync() |
||
69 | * @param \phpbu\App\Backup\Target $target |
||
70 | * @param \phpbu\App\Result $result |
||
71 | * @throws \phpbu\App\Backup\Sync\Exception |
||
72 | */ |
||
73 | 1 | public function sync(Target $target, Result $result) |
|
98 | |||
99 | /** |
||
100 | * Create a sftp handle. |
||
101 | * |
||
102 | * @return \phpseclib\Net\SFTP |
||
103 | * @throws \phpbu\App\Backup\Sync\Exception |
||
104 | */ |
||
105 | protected function login() : phpseclib\Net\SFTP |
||
126 | |||
127 | /** |
||
128 | * Return list of remote directories to travers. |
||
129 | * |
||
130 | * @return array |
||
131 | */ |
||
132 | 1 | private function getRemoteDirectoryList() : array |
|
136 | |||
137 | /** |
||
138 | * Creates collector for SFTP |
||
139 | * |
||
140 | * @param \phpbu\App\Backup\Target $target |
||
141 | * @return \phpbu\App\Backup\Collector |
||
142 | */ |
||
143 | protected function createCollector(Target $target): Collector |
||
147 | } |
||
148 |