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 | * @var phpseclib\Net\SFTP |
||
| 24 | */ |
||
| 25 | protected $sftp; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * (non-PHPDoc) |
||
| 29 | * |
||
| 30 | * @see \phpbu\App\Backup\Sync::setup() |
||
| 31 | * @param array $config |
||
| 32 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 33 | * @throws \phpbu\App\Exception |
||
| 34 | */ |
||
| 35 | 7 | public function setup(array $config) |
|
| 41 | |||
| 42 | /** |
||
| 43 | * Check for required loaded libraries or extensions. |
||
| 44 | * |
||
| 45 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 46 | */ |
||
| 47 | 7 | protected function checkRequirements() |
|
| 53 | |||
| 54 | /** |
||
| 55 | * Return implemented (*)TP protocol name. |
||
| 56 | * |
||
| 57 | * @return string |
||
| 58 | */ |
||
| 59 | 1 | protected function getProtocolName() |
|
| 63 | |||
| 64 | /** |
||
| 65 | * (non-PHPDoc) |
||
| 66 | * |
||
| 67 | * @see \phpbu\App\Backup\Sync::sync() |
||
| 68 | * @param \phpbu\App\Backup\Target $target |
||
| 69 | * @param \phpbu\App\Result $result |
||
| 70 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 71 | */ |
||
| 72 | 1 | public function sync(Target $target, Result $result) |
|
| 97 | |||
| 98 | /** |
||
| 99 | * Create a sftp handle. |
||
| 100 | * |
||
| 101 | * @return \phpseclib\Net\SFTP |
||
| 102 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 103 | */ |
||
| 104 | protected function login() : phpseclib\Net\SFTP |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Return list of remote directories to travers. |
||
| 128 | * |
||
| 129 | * @return array |
||
| 130 | */ |
||
| 131 | 1 | 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 | 1 | View Code Duplication | public function cleanup(Target $target, Result $result) |
| 160 | } |
||
| 161 |