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 Sftp extends Xtp implements Simulator |
||
20 | { |
||
21 | /** |
||
22 | * @var phpseclib\Net\SFTP |
||
23 | */ |
||
24 | protected $sftp; |
||
25 | |||
26 | /** |
||
27 | * (non-PHPDoc) |
||
28 | * |
||
29 | * @see \phpbu\App\Backup\Sync::setup() |
||
30 | * @param array $config |
||
31 | * @throws \phpbu\App\Backup\Sync\Exception |
||
32 | * @throws \phpbu\App\Exception |
||
33 | */ |
||
34 | 6 | public function setup(array $config) |
|
40 | |||
41 | /** |
||
42 | * Check for required loaded libraries or extensions. |
||
43 | * |
||
44 | * @throws \phpbu\App\Backup\Sync\Exception |
||
45 | */ |
||
46 | 6 | protected function checkRequirements() |
|
52 | |||
53 | /** |
||
54 | * Return implemented (*)TP protocol name. |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | 1 | protected function getProtocolName() |
|
62 | |||
63 | /** |
||
64 | * (non-PHPDoc) |
||
65 | * |
||
66 | * @see \phpbu\App\Backup\Sync::sync() |
||
67 | * @param \phpbu\App\Backup\Target $target |
||
68 | * @param \phpbu\App\Result $result |
||
69 | * @throws \phpbu\App\Backup\Sync\Exception |
||
70 | */ |
||
71 | public function sync(Target $target, Result $result) |
||
96 | |||
97 | /** |
||
98 | * Create a sftp handle. |
||
99 | * |
||
100 | * @return \phpseclib\Net\SFTP |
||
101 | * @throws \phpbu\App\Backup\Sync\Exception |
||
102 | */ |
||
103 | private function login() : phpseclib\Net\SFTP |
||
124 | |||
125 | /** |
||
126 | * Return list of remote directories to travers. |
||
127 | * |
||
128 | * @return array |
||
129 | */ |
||
130 | private function getRemoteDirectoryList() : array |
||
144 | |||
145 | /** |
||
146 | * Execute the remote clean up if needed |
||
147 | * |
||
148 | * @param \phpbu\App\Backup\Target $target |
||
149 | * @param \phpbu\App\Result $result |
||
150 | */ |
||
151 | View Code Duplication | public function cleanup(Target $target, Result $result) |
|
160 | } |
||
161 |