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 | /** |
||
| 23 | * Setup the Ftp sync. |
||
| 24 | * |
||
| 25 | * @param array $config |
||
| 26 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 27 | */ |
||
| 28 | 6 | public function setup(array $config) |
|
| 29 | { |
||
| 30 | 6 | $path = Arr::getValue($config, 'path', ''); |
|
| 31 | 6 | if ('/' === substr($path, 0, 1)) { |
|
| 32 | 1 | throw new Exception('absolute path is not allowed'); |
|
| 33 | } |
||
| 34 | 5 | parent::setup($config); |
|
| 35 | 2 | } |
|
| 36 | |||
| 37 | /** |
||
| 38 | * Check for required loaded libraries or extensions. |
||
| 39 | * |
||
| 40 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 41 | */ |
||
| 42 | 5 | protected function checkRequirements() |
|
| 43 | { |
||
| 44 | 5 | if (!function_exists('ftp_connect')) { |
|
| 45 | throw new Exception('ftp functions not enabled'); |
||
| 46 | } |
||
| 47 | 5 | } |
|
| 48 | |||
| 49 | /** |
||
| 50 | * Return implemented (*)TP protocol name. |
||
| 51 | * |
||
| 52 | * @return string |
||
| 53 | */ |
||
| 54 | 1 | protected function getProtocolName() |
|
| 58 | |||
| 59 | /** |
||
| 60 | * (non-PHPDoc) |
||
| 61 | * |
||
| 62 | * @see \phpbu\App\Backup\Sync::sync() |
||
| 63 | * @param \phpbu\App\Backup\Target $target |
||
| 64 | * @param \phpbu\App\Result $result |
||
| 65 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 66 | */ |
||
| 67 | public function sync(Target $target, Result $result) |
||
| 117 | } |
||
| 118 |