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 |
||
| 23 | class Dropbox implements Simulator |
||
| 24 | { |
||
| 25 | use Clearable; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * API access token |
||
| 29 | * |
||
| 30 | * Goto https://www.dropbox.com/developers/apps |
||
| 31 | * create your app |
||
| 32 | * - Dropbox api app |
||
| 33 | * - files and datastore |
||
| 34 | * - yes |
||
| 35 | * - provide some app name "my-dropbox-app" |
||
| 36 | * - generate access token to authenticate connection to your dropbox |
||
| 37 | * |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $token; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Remote path |
||
| 44 | * |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | protected $path; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Dropbox api client |
||
| 51 | * |
||
| 52 | * @var DropboxApi |
||
| 53 | */ |
||
| 54 | protected $client; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * (non-PHPDoc) |
||
| 58 | * |
||
| 59 | * @see \phpbu\App\Backup\Sync::setup() |
||
| 60 | * @param array $config |
||
| 61 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 62 | * @throws \phpbu\App\Exception |
||
| 63 | */ |
||
| 64 | 5 | public function setup(array $config) |
|
| 81 | |||
| 82 | /** |
||
| 83 | * (non-PHPDoc) |
||
| 84 | * |
||
| 85 | * @see \phpbu\App\Backup\Sync::sync() |
||
| 86 | * @param \phpbu\App\Backup\Target $target |
||
| 87 | * @param \phpbu\App\Result $result |
||
| 88 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 89 | */ |
||
| 90 | public function sync(Target $target, Result $result) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Simulate the sync execution. |
||
| 110 | * |
||
| 111 | * @param \phpbu\App\Backup\Target $target |
||
| 112 | * @param \phpbu\App\Result $result |
||
| 113 | */ |
||
| 114 | 2 | public function simulate(Target $target, Result $result) |
|
| 124 | |||
| 125 | /** |
||
| 126 | * Execute the remote clean up if needed |
||
| 127 | * |
||
| 128 | * @param \phpbu\App\Backup\Target $target |
||
| 129 | * @param \phpbu\App\Result $result |
||
| 130 | */ |
||
| 131 | View Code Duplication | public function cleanup(Target $target, Result $result) |
|
| 140 | |||
| 141 | /** |
||
| 142 | * Create Dropbox api client |
||
| 143 | */ |
||
| 144 | protected function connect() |
||
| 149 | } |
||
| 150 |