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 Sftp extends Xtp implements Simulator |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Check for required loaded libraries or extensions. |
||
| 24 | * |
||
| 25 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 26 | */ |
||
| 27 | 6 | protected function checkRequirements() |
|
| 33 | |||
| 34 | /** |
||
| 35 | * Return implemented (*)TP protocol name. |
||
| 36 | * |
||
| 37 | * @return string |
||
| 38 | */ |
||
| 39 | 1 | protected function getProtocolName() |
|
| 43 | |||
| 44 | /** |
||
| 45 | * (non-PHPDoc) |
||
| 46 | * |
||
| 47 | * @see \phpbu\App\Backup\Sync::sync() |
||
| 48 | * @param \phpbu\App\Backup\Target $target |
||
| 49 | * @param \phpbu\App\Result $result |
||
| 50 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 51 | */ |
||
| 52 | public function sync(Target $target, Result $result) |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Create a sftp handle. |
||
| 77 | * |
||
| 78 | * @return \phpseclib\Net\SFTP |
||
| 79 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 80 | */ |
||
| 81 | private function login() : phpseclib\Net\SFTP |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Return list of remote directories to travers. |
||
| 105 | * |
||
| 106 | * @return array |
||
| 107 | */ |
||
| 108 | private function getRemoteDirectoryList() : array |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Execute the remote clean up if needed |
||
| 119 | * |
||
| 120 | * @param \phpbu\App\Backup\Target $target |
||
| 121 | * @param \phpbu\App\Result $result |
||
| 122 | */ |
||
| 123 | public function cleanup(Target $target, Result $result) |
||
| 127 | } |
||
| 128 |