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 |
||
| 28 | class Openstack implements Simulator |
||
| 29 | { |
||
| 30 | use Clearable; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * OpenStack identify url |
||
| 34 | * |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | protected $authUrl; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * OpenStack region |
||
| 41 | * |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | protected $region; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var string |
||
| 48 | */ |
||
| 49 | protected $username; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | protected $password; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Object Store container name |
||
| 58 | * |
||
| 59 | * @var string |
||
| 60 | */ |
||
| 61 | protected $containerName; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * OpenStack service name |
||
| 65 | * |
||
| 66 | * @var string |
||
| 67 | */ |
||
| 68 | protected $serviceName; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Max stream upload size, files over this size have to be uploaded as Dynamic Large Objects |
||
| 72 | * |
||
| 73 | * @var int |
||
| 74 | */ |
||
| 75 | protected $maxStreamUploadSize = 5368709120; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Path where to copy the backup. |
||
| 79 | * |
||
| 80 | * @var string |
||
| 81 | */ |
||
| 82 | protected $path = ''; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var Container |
||
| 86 | */ |
||
| 87 | protected $container; |
||
| 88 | 9 | ||
| 89 | /** |
||
| 90 | 9 | * @return string |
|
| 91 | */ |
||
| 92 | public function getPath(): string |
||
| 96 | |||
| 97 | 4 | /** |
|
| 98 | 4 | * (non-PHPDoc) |
|
| 99 | 4 | * |
|
| 100 | 4 | * @see \phpbu\App\Backup\Sync::setup() |
|
| 101 | 4 | * @param array $config |
|
| 102 | 4 | * @throws \phpbu\App\Backup\Sync\Exception |
|
| 103 | 4 | * @throws \phpbu\App\Exception |
|
| 104 | 1 | */ |
|
| 105 | 1 | public function setup(array $config) |
|
| 127 | |||
| 128 | /** |
||
| 129 | * Make sure all mandatory keys are present in given config. |
||
| 130 | * |
||
| 131 | * @param array $config |
||
| 132 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 133 | */ |
||
| 134 | protected function validateConfig(array $config) |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Execute the sync. |
||
| 145 | * |
||
| 146 | * @see \phpbu\App\Backup\Sync::sync() |
||
| 147 | * @param \phpbu\App\Backup\Target $target |
||
| 148 | * @param \phpbu\App\Result $result |
||
| 149 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 150 | * @throws \OpenStack\Common\Error\BadResponseError |
||
| 151 | */ |
||
| 152 | public function sync(Target $target, Result $result) |
||
| 181 | 1 | ||
| 182 | 1 | /** |
|
| 183 | 1 | * Simulate the sync execution. |
|
| 184 | 1 | * |
|
| 185 | 1 | * @param \phpbu\App\Backup\Target $target |
|
| 186 | 1 | * @param \phpbu\App\Result $result |
|
| 187 | */ |
||
| 188 | 1 | public function simulate(Target $target, Result $result) |
|
| 201 | |||
| 202 | /** |
||
| 203 | * Execute the remote clean up if needed |
||
| 204 | * |
||
| 205 | * @param \phpbu\App\Backup\Target $target |
||
| 206 | * @param \phpbu\App\Result $result |
||
| 207 | */ |
||
| 208 | View Code Duplication | public function cleanup(Target $target, Result $result) |
|
| 217 | |||
| 218 | /** |
||
| 219 | * @param ObjectStoreService $service |
||
| 220 | * @return \OpenStack\ObjectStore\v1\Models\Container |
||
| 221 | * @throws \OpenStack\Common\Error\BadResponseError |
||
| 222 | */ |
||
| 223 | protected function getOrCreateContainer(ObjectStoreService $service, Result $result) |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Get the upload path |
||
| 234 | * |
||
| 235 | * @param \phpbu\App\Backup\Target $target |
||
| 236 | * @return string |
||
| 237 | */ |
||
| 238 | public function getUploadPath(Target $target) |
||
| 242 | |||
| 243 | /** |
||
| 244 | * @param Result $result |
||
| 245 | * @return void |
||
| 246 | * @throws \OpenStack\Common\Error\BadResponseError |
||
| 247 | */ |
||
| 248 | protected function connect(Result $result) |
||
| 267 | } |
||
| 268 |