Complex classes like Rsync often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Rsync, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | class Rsync extends AbstractProtocol |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | protected $executable = "/usr/bin/rsync"; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var bool |
||
| 29 | */ |
||
| 30 | protected $archive = true; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var bool |
||
| 34 | */ |
||
| 35 | protected $skipNewerFiles = false; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var bool |
||
| 39 | */ |
||
| 40 | protected $followSymLinks = true; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var bool |
||
| 44 | */ |
||
| 45 | protected $dryRun = false; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var array |
||
| 49 | */ |
||
| 50 | protected $optionalParameters = array(); |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var bool |
||
| 54 | */ |
||
| 55 | protected $verbose = false; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var bool |
||
| 59 | */ |
||
| 60 | protected $deleteFromTarget = false; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var bool |
||
| 64 | */ |
||
| 65 | protected $deleteExcluded = false; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @var array |
||
| 69 | */ |
||
| 70 | protected $exclude = array(); |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @var string |
||
| 74 | */ |
||
| 75 | protected $excludeFrom = null; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @var bool |
||
| 79 | */ |
||
| 80 | protected $recursive = true; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @var bool |
||
| 84 | */ |
||
| 85 | protected $times = false; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @var bool |
||
| 89 | */ |
||
| 90 | protected $showOutput = true; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @var bool |
||
| 94 | */ |
||
| 95 | protected $compression = false; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @var bool |
||
| 99 | */ |
||
| 100 | protected $remoteOrigin = false; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @var bool |
||
| 104 | */ |
||
| 105 | protected $removeSource = false; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @var bool |
||
| 109 | */ |
||
| 110 | protected $info = false; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @var SSH |
||
| 114 | */ |
||
| 115 | protected $ssh; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Injects and validates config |
||
| 119 | * |
||
| 120 | * @param array $options |
||
| 121 | */ |
||
| 122 | public function __construct(Array $options = array()) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @param $options |
||
| 147 | */ |
||
| 148 | public function setSshOptions($options) |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Sync $origin directory with $target one. |
||
| 156 | * If SSH was configured, you must use absolute path |
||
| 157 | * in the target directory |
||
| 158 | * |
||
| 159 | * @param $origin |
||
| 160 | * @param $target |
||
| 161 | * |
||
| 162 | * @throws \InvalidArgumentException If the command failed |
||
| 163 | */ |
||
| 164 | public function sync($origin, $target) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @return string |
||
| 173 | */ |
||
| 174 | public function getExecutable() |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @return bool |
||
| 181 | */ |
||
| 182 | public function getArchive() |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @param $archive |
||
| 189 | */ |
||
| 190 | public function setArchive($archive) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @param $skipNewerFiles |
||
| 197 | */ |
||
| 198 | public function setSkipNewerFiles($skipNewerFiles) |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @return bool |
||
| 205 | */ |
||
| 206 | public function getSkipNewerFiles() |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @param $followSymLinks |
||
| 213 | */ |
||
| 214 | public function setFollowSymLinks($followSymLinks) |
||
| 218 | |||
| 219 | /** |
||
| 220 | * @return bool |
||
| 221 | */ |
||
| 222 | public function getFollowSymLinks() |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @param $dryRun |
||
| 229 | */ |
||
| 230 | public function setDryRun($dryRun) |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @return bool |
||
| 237 | */ |
||
| 238 | public function getDryRun() |
||
| 242 | |||
| 243 | /** |
||
| 244 | * @param $optionalParameters |
||
| 245 | */ |
||
| 246 | public function setOptionalParameters($optionalParameters) |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @return array |
||
| 253 | */ |
||
| 254 | public function getOptionalParameters() |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @param $verbose |
||
| 261 | */ |
||
| 262 | public function setVerbose($verbose) |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @return bool |
||
| 269 | */ |
||
| 270 | public function getVerbose() |
||
| 274 | |||
| 275 | /** |
||
| 276 | * @param $deleteExcluded |
||
| 277 | */ |
||
| 278 | public function setDeleteExcluded($deleteExcluded) |
||
| 282 | |||
| 283 | /** |
||
| 284 | * @return bool |
||
| 285 | */ |
||
| 286 | public function getDeleteExcluded() |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @param $deleteFromTarget |
||
| 293 | */ |
||
| 294 | public function setDeleteFromTarget($deleteFromTarget) |
||
| 298 | |||
| 299 | /** |
||
| 300 | * @return bool |
||
| 301 | */ |
||
| 302 | public function getDeleteFromTarget() |
||
| 306 | |||
| 307 | /** |
||
| 308 | * @param $exclude |
||
| 309 | */ |
||
| 310 | public function setExclude($exclude) |
||
| 314 | |||
| 315 | /** |
||
| 316 | * @return array |
||
| 317 | */ |
||
| 318 | public function getExclude() |
||
| 322 | |||
| 323 | /** |
||
| 324 | * @param $exclude |
||
| 325 | */ |
||
| 326 | public function setExcludeFrom($excludeFrom) |
||
| 330 | |||
| 331 | /** |
||
| 332 | * @return string |
||
| 333 | */ |
||
| 334 | public function getExcludeFrom() |
||
| 338 | |||
| 339 | /** |
||
| 340 | * @param $recursive |
||
| 341 | */ |
||
| 342 | public function setRecursive($recursive) |
||
| 346 | |||
| 347 | /** |
||
| 348 | * @return bool |
||
| 349 | */ |
||
| 350 | public function getRecursive() |
||
| 354 | |||
| 355 | /** |
||
| 356 | * @param bool $times |
||
| 357 | */ |
||
| 358 | public function setTimes($times) |
||
| 362 | |||
| 363 | /** |
||
| 364 | * @return bool |
||
| 365 | */ |
||
| 366 | public function getTimes() |
||
| 370 | |||
| 371 | /** |
||
| 372 | * @param $showOutput |
||
| 373 | */ |
||
| 374 | public function setShowOutput($showOutput) |
||
| 378 | |||
| 379 | /** |
||
| 380 | * @return bool |
||
| 381 | */ |
||
| 382 | public function getShowOutput() |
||
| 386 | |||
| 387 | /** |
||
| 388 | * @param $compression |
||
| 389 | */ |
||
| 390 | public function setCompression($compression) |
||
| 394 | |||
| 395 | /** |
||
| 396 | * @return bool |
||
| 397 | */ |
||
| 398 | public function getCompression() |
||
| 402 | |||
| 403 | /** |
||
| 404 | * @param $remoteOrigin |
||
| 405 | */ |
||
| 406 | public function setRemoteOrigin($remoteOrigin) |
||
| 410 | |||
| 411 | /** |
||
| 412 | * @return bool |
||
| 413 | */ |
||
| 414 | public function getRemoteOrigin() |
||
| 418 | |||
| 419 | /** |
||
| 420 | * @param $removeSource |
||
| 421 | */ |
||
| 422 | public function setRemoveSource($removeSource) |
||
| 426 | |||
| 427 | /** |
||
| 428 | * @return bool |
||
| 429 | */ |
||
| 430 | public function getRemoveSource() |
||
| 434 | |||
| 435 | /** |
||
| 436 | * @param $info |
||
| 437 | */ |
||
| 438 | public function setInfo($info) |
||
| 442 | |||
| 443 | /** |
||
| 444 | * @return bool |
||
| 445 | */ |
||
| 446 | public function getInfo() |
||
| 450 | |||
| 451 | /** |
||
| 452 | * Gets command generated for this current |
||
| 453 | * rsync configuration. You can use it to test |
||
| 454 | * or execute it later without using the sync method |
||
| 455 | * |
||
| 456 | * @param $origin |
||
| 457 | * @param $target |
||
| 458 | * |
||
| 459 | * @return Command |
||
| 460 | */ |
||
| 461 | public function getCommand($origin, $target) |
||
| 556 | } |
||
| 557 |