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(  | 
            ||
| 228 | |||
| 229 | |||
| 230 | /**  | 
            ||
| 231 | * createCircle();  | 
            ||
| 232 | *  | 
            ||
| 233 | * Create a circle with $userId as its owner.  | 
            ||
| 234 | * Will returns the circle  | 
            ||
| 235 | *  | 
            ||
| 236 | * @param DeprecatedCircle $circle  | 
            ||
| 237 | */  | 
            ||
| 238 | 	public function createCircle(DeprecatedCircle $circle) { | 
            ||
| 255 | |||
| 256 | |||
| 257 | /**  | 
            ||
| 258 | * remove a circle  | 
            ||
| 259 | *  | 
            ||
| 260 | * @param string $circleUniqueId  | 
            ||
| 261 | */  | 
            ||
| 262 | 	public function destroyCircle($circleUniqueId) { | 
            ||
| 267 | |||
| 268 | |||
| 269 | /**  | 
            ||
| 270 | * returns if the circle is already in database  | 
            ||
| 271 | *  | 
            ||
| 272 | * @param DeprecatedCircle $circle  | 
            ||
| 273 | * @param string $userId  | 
            ||
| 274 | *  | 
            ||
| 275 | * @return bool  | 
            ||
| 276 | * @throws ConfigNoCircleAvailableException  | 
            ||
| 277 | */  | 
            ||
| 278 | 	public function isCircleUnique(DeprecatedCircle $circle, $userId = '') { | 
            ||
| 297 | |||
| 298 | |||
| 299 | /**  | 
            ||
| 300 | * return if the personal circle is unique  | 
            ||
| 301 | *  | 
            ||
| 302 | * @param DeprecatedCircle $circle  | 
            ||
| 303 | * @param string $userId  | 
            ||
| 304 | *  | 
            ||
| 305 | * @return bool  | 
            ||
| 306 | * @throws ConfigNoCircleAvailableException  | 
            ||
| 307 | */  | 
            ||
| 308 | 	private function isPersonalCircleUnique(DeprecatedCircle $circle, $userId = '') { | 
            ||
| 327 | |||
| 328 | |||
| 329 | /**  | 
            ||
| 330 | * @param DeprecatedCircle $circle  | 
            ||
| 331 | * @param string $userId  | 
            ||
| 332 | *  | 
            ||
| 333 | * @throws CircleAlreadyExistsException  | 
            ||
| 334 | * @throws ConfigNoCircleAvailableException  | 
            ||
| 335 | */  | 
            ||
| 336 | 	public function updateCircle(DeprecatedCircle $circle, $userId = '') { | 
            ||
| 350 | |||
| 351 | |||
| 352 | /**  | 
            ||
| 353 | * @param string $uniqueId  | 
            ||
| 354 | *  | 
            ||
| 355 | * @return DeprecatedCircle  | 
            ||
| 356 | * @throws CircleDoesNotExistException  | 
            ||
| 357 | */  | 
            ||
| 358 | View Code Duplication | 	public function getCircleFromUniqueId($uniqueId) { | 
            |
| 372 | |||
| 373 | |||
| 374 | /**  | 
            ||
| 375 | * @param int $addressBookId  | 
            ||
| 376 | *  | 
            ||
| 377 | * @return array  | 
            ||
| 378 | */  | 
            ||
| 379 | 	public function getFromBook(int $addressBookId) { | 
            ||
| 392 | |||
| 393 | |||
| 394 | /**  | 
            ||
| 395 | * @param int $addressBookId  | 
            ||
| 396 | *  | 
            ||
| 397 | * @return DeprecatedCircle[]  | 
            ||
| 398 | */  | 
            ||
| 399 | View Code Duplication | 	public function getFromContactBook(int $addressBookId): array { | 
            |
| 416 | |||
| 417 | |||
| 418 | /**  | 
            ||
| 419 | * @param int $addressBookId  | 
            ||
| 420 | * @param string $group  | 
            ||
| 421 | *  | 
            ||
| 422 | * @return DeprecatedCircle  | 
            ||
| 423 | * @throws CircleDoesNotExistException  | 
            ||
| 424 | */  | 
            ||
| 425 | View Code Duplication | 	public function getFromContactGroup(int $addressBookId, string $group): DeprecatedCircle { | 
            |
| 440 | |||
| 441 | }  | 
            ||
| 442 | 
This class, trait or interface has been deprecated.