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:
Complex classes like DeprecatedCirclesRequest 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 DeprecatedCirclesRequest, and based on these observations, apply Extract Interface, too.
| 1 | <?php declare(strict_types=1); |
||
| 40 | class DeprecatedCirclesRequest extends DeprecatedCirclesRequestBuilder { |
||
| 41 | |||
| 42 | |||
| 43 | /** |
||
| 44 | * forceGetCircle(); |
||
| 45 | * |
||
| 46 | * returns data of a circle from its Id. |
||
| 47 | * |
||
| 48 | * WARNING: This function does not filters data regarding the current user/viewer. |
||
| 49 | * In case of interaction with users, Please use getCircle() instead. |
||
| 50 | * |
||
| 51 | * @param string $circleUniqueId |
||
| 52 | * @param bool $allSettings |
||
| 53 | * |
||
| 54 | * @return DeprecatedCircle |
||
| 55 | * @throws CircleDoesNotExistException |
||
| 56 | */ |
||
| 57 | public function forceGetCircle($circleUniqueId, bool $allSettings = false) { |
||
| 73 | |||
| 74 | |||
| 75 | /** |
||
| 76 | * forceGetCircles(); |
||
| 77 | * |
||
| 78 | * returns data of a all circles. |
||
| 79 | * |
||
| 80 | * WARNING: This function does not filters data regarding the current user/viewer. |
||
| 81 | * In case of interaction with users, Please use getCircles() instead. |
||
| 82 | * |
||
| 83 | * @param string $ownerId |
||
| 84 | * |
||
| 85 | * @return DeprecatedCircle[] |
||
| 86 | */ |
||
| 87 | View Code Duplication | public function forceGetCircles(string $ownerId = '') { |
|
| 100 | |||
| 101 | |||
| 102 | /** |
||
| 103 | * forceGetCircleByName(); |
||
| 104 | * |
||
| 105 | * returns data of a circle from its Name. |
||
| 106 | * |
||
| 107 | * WARNING: This function does not filters data regarding the current user/viewer. |
||
| 108 | * In case of interaction with users, do not use this method. |
||
| 109 | * |
||
| 110 | * @param $name |
||
| 111 | * |
||
| 112 | * @return null|DeprecatedCircle |
||
| 113 | * @throws CircleDoesNotExistException |
||
| 114 | */ |
||
| 115 | View Code Duplication | public function forceGetCircleByName($name) { |
|
| 131 | |||
| 132 | |||
| 133 | /** |
||
| 134 | * @param string $userId |
||
| 135 | * @param int $circleType |
||
| 136 | * @param string $name |
||
| 137 | * @param int $level |
||
| 138 | * @param bool $forceAll |
||
| 139 | * @param string $ownerId |
||
| 140 | * |
||
| 141 | * @return DeprecatedCircle[] |
||
| 142 | * @throws ConfigNoCircleAvailableException |
||
| 143 | * @throws GSStatusException |
||
| 144 | */ |
||
| 145 | public function getCircles( |
||
| 178 | |||
| 179 | |||
| 180 | /** |
||
| 181 | * |
||
| 182 | * @param string $circleUniqueId |
||
| 183 | * @param string $viewerId |
||
| 184 | * @param int $type |
||
| 185 | * @param string $instanceId |
||
| 186 | * @param bool $forceAll |
||
| 187 | * |
||
| 188 | * @return DeprecatedCircle |
||
| 189 | * @throws CircleDoesNotExistException |
||
| 190 | * @throws ConfigNoCircleAvailableException |
||
| 191 | */ |
||
| 192 | public function getCircle( |
||
| 225 | |||
| 226 | |||
| 227 | /** |
||
| 228 | * createCircle(); |
||
| 229 | * |
||
| 230 | * Create a circle with $userId as its owner. |
||
| 231 | * Will returns the circle |
||
| 232 | * |
||
| 233 | * @param DeprecatedCircle $circle |
||
| 234 | */ |
||
| 235 | View Code Duplication | public function createCircle(DeprecatedCircle $circle) { |
|
| 248 | |||
| 249 | |||
| 250 | /** |
||
| 251 | * remove a circle |
||
| 252 | * |
||
| 253 | * @param string $circleUniqueId |
||
| 254 | */ |
||
| 255 | public function destroyCircle($circleUniqueId) { |
||
| 260 | |||
| 261 | |||
| 262 | /** |
||
| 263 | * returns if the circle is already in database |
||
| 264 | * |
||
| 265 | * @param DeprecatedCircle $circle |
||
| 266 | * @param string $userId |
||
| 267 | * |
||
| 268 | * @return bool |
||
| 269 | * @throws ConfigNoCircleAvailableException |
||
| 270 | */ |
||
| 271 | public function isCircleUnique(DeprecatedCircle $circle, $userId = '') { |
||
| 290 | |||
| 291 | |||
| 292 | /** |
||
| 293 | * return if the personal circle is unique |
||
| 294 | * |
||
| 295 | * @param DeprecatedCircle $circle |
||
| 296 | * @param string $userId |
||
| 297 | * |
||
| 298 | * @return bool |
||
| 299 | * @throws ConfigNoCircleAvailableException |
||
| 300 | */ |
||
| 301 | private function isPersonalCircleUnique(DeprecatedCircle $circle, $userId = '') { |
||
| 320 | |||
| 321 | |||
| 322 | /** |
||
| 323 | * @param DeprecatedCircle $circle |
||
| 324 | * @param string $userId |
||
| 325 | * |
||
| 326 | * @throws CircleAlreadyExistsException |
||
| 327 | * @throws ConfigNoCircleAvailableException |
||
| 328 | */ |
||
| 329 | public function updateCircle(DeprecatedCircle $circle, $userId = '') { |
||
| 343 | |||
| 344 | |||
| 345 | /** |
||
| 346 | * @param string $uniqueId |
||
| 347 | * |
||
| 348 | * @return DeprecatedCircle |
||
| 349 | * @throws CircleDoesNotExistException |
||
| 350 | */ |
||
| 351 | View Code Duplication | public function getCircleFromUniqueId($uniqueId) { |
|
| 365 | |||
| 366 | |||
| 367 | /** |
||
| 368 | * @param int $addressBookId |
||
| 369 | * |
||
| 370 | * @return array |
||
| 371 | */ |
||
| 372 | public function getFromBook(int $addressBookId) { |
||
| 385 | |||
| 386 | |||
| 387 | /** |
||
| 388 | * @param int $addressBookId |
||
| 389 | * |
||
| 390 | * @return DeprecatedCircle[] |
||
| 391 | */ |
||
| 392 | View Code Duplication | public function getFromContactBook(int $addressBookId): array { |
|
| 409 | |||
| 410 | |||
| 411 | /** |
||
| 412 | * @param int $addressBookId |
||
| 413 | * @param string $group |
||
| 414 | * |
||
| 415 | * @return DeprecatedCircle |
||
| 416 | * @throws CircleDoesNotExistException |
||
| 417 | */ |
||
| 418 | View Code Duplication | public function getFromContactGroup(int $addressBookId, string $group): DeprecatedCircle { |
|
| 433 | |||
| 434 | } |
||
| 435 |
This class, trait or interface has been deprecated.