Complex classes like Client 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 Client, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class Client { |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var ServiceInterface $service |
||
| 18 | */ |
||
| 19 | protected $service; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Initiate this class with a subclass of ServiceInterface. There are two |
||
| 23 | * service subclasses available: |
||
| 24 | * - Service\REST: Service which makes calls to the live Strava API |
||
| 25 | * - Service\Stub: Service stub for test purposes (unit tests) |
||
| 26 | * |
||
| 27 | * @param ServiceInterface $service |
||
| 28 | */ |
||
| 29 | 72 | public function __construct(ServiceInterface $service) { |
|
| 32 | |||
| 33 | /** |
||
| 34 | * Retrieve current athlete |
||
| 35 | * |
||
| 36 | * @link http://strava.github.io/api/v3/athlete/#get-details, |
||
| 37 | * http://strava.github.io/api/v3/athlete/#get-another-details |
||
| 38 | * @param int $id |
||
| 39 | * @return array |
||
| 40 | * @throws Exception |
||
| 41 | */ |
||
| 42 | 2 | public function getAthlete($id = null) { |
|
| 49 | |||
| 50 | /** |
||
| 51 | * Retrieve athlete stats |
||
| 52 | * |
||
| 53 | * Only available for the authenticated athlete. |
||
| 54 | * |
||
| 55 | * @link http://strava.github.io/api/v3/athlete/#stats |
||
| 56 | * @param int $id |
||
| 57 | * @return array |
||
| 58 | * @throws ClientException |
||
| 59 | */ |
||
| 60 | 1 | public function getAthleteStats($id) { |
|
| 61 | try { |
||
| 62 | 1 | return $this->service->getAthleteStats($id); |
|
| 63 | } catch (ServiceException $e) { |
||
| 64 | throw new ClientException('[SERVICE] '.$e->getMessage()); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * List athlete clubs |
||
| 70 | * |
||
| 71 | * @link http://strava.github.io/api/v3/clubs/#get-athletes |
||
| 72 | * @return array |
||
| 73 | * @throws Exception |
||
| 74 | */ |
||
| 75 | 2 | public function getAthleteClubs() { |
|
| 82 | |||
| 83 | /** |
||
| 84 | * List athlete activities |
||
| 85 | * |
||
| 86 | * @link http://strava.github.io/api/v3/activities/#get-activities |
||
| 87 | * @param string $before |
||
| 88 | * @param string $after |
||
| 89 | * @param int $page |
||
| 90 | * @param int $per_page |
||
| 91 | * @return array |
||
| 92 | * @throws Exception |
||
| 93 | */ |
||
| 94 | 2 | public function getAthleteActivities($before = null, $after = null, $page = null, $per_page = null) { |
|
| 101 | |||
| 102 | /** |
||
| 103 | * List athlete friends |
||
| 104 | * |
||
| 105 | * @link http://strava.github.io/api/v3/follow/#friends |
||
| 106 | * @param int $id |
||
| 107 | * @param int $page |
||
| 108 | * @param int $per_page |
||
| 109 | * @return array |
||
| 110 | * @throws Exception |
||
| 111 | */ |
||
| 112 | 2 | public function getAthleteFriends($id = null, $page = null, $per_page = null) { |
|
| 119 | |||
| 120 | /** |
||
| 121 | * List athlete followers |
||
| 122 | * |
||
| 123 | * @link http://strava.github.io/api/v3/follow/#followers |
||
| 124 | * @param int $id |
||
| 125 | * @param int $page |
||
| 126 | * @param int $per_page |
||
| 127 | * @return array |
||
| 128 | * @throws Exception |
||
| 129 | */ |
||
| 130 | 2 | public function getAthleteFollowers($id = null, $page = null, $per_page = null) { |
|
| 137 | |||
| 138 | /** |
||
| 139 | * List both following |
||
| 140 | * |
||
| 141 | * @link http://strava.github.io/api/v3/follow/#both |
||
| 142 | * @param int $id |
||
| 143 | * @param int $page |
||
| 144 | * @param int $per_page |
||
| 145 | * @return array |
||
| 146 | * @throws Exception |
||
| 147 | */ |
||
| 148 | 2 | public function getAthleteBothFollowing($id, $page = null, $per_page = null) { |
|
| 155 | |||
| 156 | /** |
||
| 157 | * List athlete K/QOMs/CRs |
||
| 158 | * |
||
| 159 | * @link http://strava.github.io/api/v3/athlete/#koms |
||
| 160 | * @param int $id |
||
| 161 | * @param int $page |
||
| 162 | * @param int $per_page |
||
| 163 | * @return array |
||
| 164 | * @throws Exception |
||
| 165 | */ |
||
| 166 | 2 | public function getAthleteKom($id, $page = null, $per_page = null) { |
|
| 173 | |||
| 174 | /** |
||
| 175 | * List starred segment |
||
| 176 | * |
||
| 177 | * @link http://strava.github.io/api/v3/segments/#starred |
||
| 178 | * @param int $id |
||
| 179 | * @param int $page |
||
| 180 | * @param int $per_page |
||
| 181 | * @return array |
||
| 182 | * @throws Exception |
||
| 183 | */ |
||
| 184 | 2 | public function getAthleteStarredSegments($id = null, $page = null, $per_page = null) { |
|
| 191 | |||
| 192 | /** |
||
| 193 | * Update current athlete |
||
| 194 | * |
||
| 195 | * @link http://strava.github.io/api/v3/athlete/#update |
||
| 196 | * @param string $city |
||
| 197 | * @param string $state |
||
| 198 | * @param string $country |
||
| 199 | * @param string $sex |
||
| 200 | * @param float $weight |
||
| 201 | * @return array |
||
| 202 | * @throws Exception |
||
| 203 | */ |
||
| 204 | 2 | public function updateAthlete($city, $state, $country, $sex, $weight){ |
|
| 211 | |||
| 212 | /** |
||
| 213 | * Retrieve activity from user followers |
||
| 214 | * |
||
| 215 | * @link https://strava.github.io/api/v3/activities/#get-feed |
||
| 216 | * |
||
| 217 | * @param type $before |
||
| 218 | * @param type $page |
||
| 219 | * @param type $per_page |
||
| 220 | * @return type |
||
| 221 | * @throws ClientException |
||
| 222 | 2 | */ |
|
| 223 | public function getAthleteActivitiesFollowing($before = null, $page = null, $per_page = null) { |
||
| 230 | |||
| 231 | |||
| 232 | /** |
||
| 233 | * Retrieve an activity |
||
| 234 | * |
||
| 235 | * @link http://strava.github.io/api/v3/athlete/#get-details, |
||
| 236 | * http://strava.github.io/api/v3/athlete/#get-another-details |
||
| 237 | * @param int $id |
||
| 238 | * @param boolean $include_all_efforts |
||
| 239 | * @return array |
||
| 240 | * @throws Exception |
||
| 241 | 2 | */ |
|
| 242 | public function getActivity($id, $include_all_efforts = null) { |
||
| 249 | |||
| 250 | /** |
||
| 251 | * List activity comments |
||
| 252 | * |
||
| 253 | * @link http://strava.github.io/api/v3/comments/#list |
||
| 254 | * @param int $id |
||
| 255 | * @param boolean $markdown |
||
| 256 | * @param int $page |
||
| 257 | * @param int $per_page |
||
| 258 | * @return array |
||
| 259 | 2 | * @throws Exception |
|
| 260 | */ |
||
| 261 | 2 | public function getActivityComments($id, $markdown = null, $page = null, $per_page = null) { |
|
| 268 | |||
| 269 | /** |
||
| 270 | * List activity kudoers |
||
| 271 | * |
||
| 272 | * @link http://strava.github.io/api/v3/kudos/#list |
||
| 273 | * @param int $id |
||
| 274 | * @param int $page |
||
| 275 | * @param int $per_page |
||
| 276 | * @return array |
||
| 277 | 2 | * @throws Exception |
|
| 278 | */ |
||
| 279 | 2 | public function getActivityKudos($id, $page = null, $per_page = null) { |
|
| 286 | |||
| 287 | /** |
||
| 288 | * List activity photos |
||
| 289 | * |
||
| 290 | * @link http://strava.github.io/api/v3/photos/#list |
||
| 291 | * @param int $id |
||
| 292 | * @param int $size In pixels. |
||
| 293 | 2 | * @param string $photo_sources Must be "true". |
|
| 294 | * @return array |
||
| 295 | 2 | * @throws Exception |
|
| 296 | 1 | */ |
|
| 297 | 1 | public function getActivityPhotos($id, $size = 2048, $photo_sources = 'true') { |
|
| 304 | |||
| 305 | /** |
||
| 306 | * List activity zones |
||
| 307 | * |
||
| 308 | * @link http://strava.github.io/api/v3/activities/#zones |
||
| 309 | 2 | * @param int $id |
|
| 310 | * @return array |
||
| 311 | 2 | * @throws Exception |
|
| 312 | 1 | */ |
|
| 313 | 1 | public function getActivityZones($id) { |
|
| 320 | |||
| 321 | /** |
||
| 322 | * List activity laps |
||
| 323 | * |
||
| 324 | * @link http://strava.github.io/api/v3/activities/#laps |
||
| 325 | 2 | * @param int $id |
|
| 326 | * @return array |
||
| 327 | 2 | * @throws Exception |
|
| 328 | 1 | */ |
|
| 329 | 1 | public function getActivityLaps($id) { |
|
| 336 | |||
| 337 | /** |
||
| 338 | * Check upload status |
||
| 339 | * |
||
| 340 | * @link http://strava.github.io/api/v3/uploads/#get-status |
||
| 341 | * @param int $id |
||
| 342 | * @return array |
||
| 343 | * @throws Exception |
||
| 344 | */ |
||
| 345 | public function getActivityUploadStatus($id) { |
||
| 352 | |||
| 353 | /** |
||
| 354 | * Create an activity |
||
| 355 | * |
||
| 356 | * @link http://strava.github.io/api/v3/activities/#create |
||
| 357 | * @param string $name |
||
| 358 | * @param string $type |
||
| 359 | * @param string $start_date_local |
||
| 360 | * @param int $elapsed_time |
||
| 361 | * @param string $description |
||
| 362 | * @param float $distance |
||
| 363 | * @return array |
||
| 364 | * @throws Exception |
||
| 365 | */ |
||
| 366 | public function createActivity($name, $type, $start_date_local, $elapsed_time, $description = null, $distance = null) { |
||
| 373 | 1 | ||
| 374 | 1 | /** |
|
| 375 | * Upload an activity |
||
| 376 | * |
||
| 377 | * @link http://strava.github.io/api/v3/uploads/#post-file |
||
| 378 | * @param mixed $file |
||
| 379 | * @param string $activity_type |
||
| 380 | * @param string $name |
||
| 381 | * @param string $description |
||
| 382 | * @param int $private |
||
| 383 | * @param int $trainer |
||
| 384 | * @param int $commute |
||
| 385 | * @param string $data_type |
||
| 386 | * @param string $external_id |
||
| 387 | * @return array |
||
| 388 | * @throws Exception |
||
| 389 | */ |
||
| 390 | public function uploadActivity($file, $activity_type = null, $name = null, $description = null, $private = null, $trainer = null, $commute = null, $data_type = null, $external_id = null) { |
||
| 397 | 1 | ||
| 398 | /** |
||
| 399 | * Update an activity |
||
| 400 | * |
||
| 401 | * @link http://strava.github.io/api/v3/activities/#put-updates |
||
| 402 | * @param int $id |
||
| 403 | * @param string $name |
||
| 404 | * @param string $type |
||
| 405 | * @param boolean $private |
||
| 406 | * @param boolean $commute |
||
| 407 | * @param boolean $trainer |
||
| 408 | * @param string $gear_id |
||
| 409 | 2 | * @param string $description |
|
| 410 | * @return array |
||
| 411 | 2 | * @throws Exception |
|
| 412 | 1 | */ |
|
| 413 | 1 | public function updateActivity($id, $name = null, $type = null, $private = false, $commute = false, $trainer = false, $gear_id = null, $description = null) { |
|
| 420 | |||
| 421 | /** |
||
| 422 | * Delete an activity |
||
| 423 | * |
||
| 424 | * @link http://strava.github.io/api/v3/activities/#delete |
||
| 425 | * @param int $id |
||
| 426 | 2 | * @return array |
|
| 427 | * @throws Exception |
||
| 428 | 2 | */ |
|
| 429 | 1 | public function deleteActivity($id) { |
|
| 436 | |||
| 437 | |||
| 438 | /** |
||
| 439 | * Retrieve gear |
||
| 440 | * |
||
| 441 | * @link http://strava.github.io/api/v3/gear/ |
||
| 442 | 2 | * @param int $id |
|
| 443 | * @return array |
||
| 444 | 2 | * @throws Exception |
|
| 445 | 1 | */ |
|
| 446 | 1 | public function getGear($id) { |
|
| 453 | |||
| 454 | /** |
||
| 455 | * Retrieve a club |
||
| 456 | * |
||
| 457 | * @link http://strava.github.io/api/v3/clubs/#get-details |
||
| 458 | * @param int $id |
||
| 459 | * @return array |
||
| 460 | 2 | * @throws Exception |
|
| 461 | */ |
||
| 462 | 2 | public function getClub($id) { |
|
| 469 | |||
| 470 | /** |
||
| 471 | * List club members |
||
| 472 | * |
||
| 473 | * @link http://strava.github.io/api/v3/clubs/#get-members |
||
| 474 | * @param int $id |
||
| 475 | * @param int $page |
||
| 476 | * @param int $per_page |
||
| 477 | * @return array |
||
| 478 | 2 | * @throws Exception |
|
| 479 | */ |
||
| 480 | 2 | public function getClubMembers($id, $page = null, $per_page = null) { |
|
| 487 | |||
| 488 | /** |
||
| 489 | * List club activities |
||
| 490 | * |
||
| 491 | * @link http://strava.github.io/api/v3/clubs/#get-activities |
||
| 492 | * @param int $id |
||
| 493 | * @param int $page |
||
| 494 | 2 | * @param int $per_page |
|
| 495 | * @return array |
||
| 496 | 2 | * @throws Exception |
|
| 497 | 1 | */ |
|
| 498 | 1 | public function getClubActivities($id, $page = null, $per_page = null) { |
|
| 505 | |||
| 506 | /** |
||
| 507 | * List club announcements |
||
| 508 | * |
||
| 509 | * @link https://strava.github.io/api/v3/clubs/#get-announcements |
||
| 510 | 2 | * @param int $id |
|
| 511 | * @return array |
||
| 512 | 2 | * @throws Exception |
|
| 513 | 1 | */ |
|
| 514 | 1 | public function getClubAnnouncements($id) { |
|
| 521 | |||
| 522 | /** |
||
| 523 | * List club group events |
||
| 524 | * |
||
| 525 | * @link https://strava.github.io/api/v3/clubs/#get-group-events |
||
| 526 | 2 | * @param int $id |
|
| 527 | * @return array |
||
| 528 | 2 | * @throws Exception |
|
| 529 | 1 | */ |
|
| 530 | 1 | public function getClubGroupEvents($id) { |
|
| 537 | |||
| 538 | /** |
||
| 539 | * Join a club |
||
| 540 | * |
||
| 541 | * @link https://strava.github.io/api/v3/clubs/#join |
||
| 542 | 2 | * @param int $id |
|
| 543 | * @return array |
||
| 544 | 2 | * @throws Exception |
|
| 545 | 1 | */ |
|
| 546 | 1 | public function joinClub($id) { |
|
| 553 | |||
| 554 | /** |
||
| 555 | * Leave a club |
||
| 556 | * |
||
| 557 | * @link https://strava.github.io/api/v3/clubs/#leave |
||
| 558 | 2 | * @param int $id |
|
| 559 | * @return array |
||
| 560 | 2 | * @throws Exception |
|
| 561 | 1 | */ |
|
| 562 | 1 | public function leaveClub($id) { |
|
| 569 | |||
| 570 | /** |
||
| 571 | * Retrieve a segment |
||
| 572 | * |
||
| 573 | * @link http://strava.github.io/api/v3/segments/#retrieve |
||
| 574 | * @param int $id |
||
| 575 | * @return array |
||
| 576 | * @throws Exception |
||
| 577 | */ |
||
| 578 | public function getSegment($id) { |
||
| 585 | 2 | ||
| 586 | 1 | /** |
|
| 587 | 1 | * Segment leaderboards |
|
| 588 | * |
||
| 589 | * @link http://strava.github.io/api/v3/segments/#leaderboard |
||
| 590 | * @param int $id |
||
| 591 | * @param string $gender |
||
| 592 | * @param string $age_group |
||
| 593 | * @param string $weight_class |
||
| 594 | * @param boolean $following |
||
| 595 | * @param int $club_id |
||
| 596 | * @param string $date_range |
||
| 597 | * @param int $context_entries |
||
| 598 | * @param int $page |
||
| 599 | * @param int $per_page |
||
| 600 | * @return array |
||
| 601 | * @throws Exception |
||
| 602 | 2 | */ |
|
| 603 | public function getSegmentLeaderboard($id, $gender = null, $age_group = null, $weight_class = null, $following = null, $club_id = null, $date_range = null, $context_entries = null, $page = null, $per_page = null) { |
||
| 610 | |||
| 611 | /** |
||
| 612 | * Segment explorer |
||
| 613 | * |
||
| 614 | * @link http://strava.github.io/api/v3/segments/#explore |
||
| 615 | * @param string $bounds |
||
| 616 | * @param string $activity_type |
||
| 617 | * @param int $min_cat |
||
| 618 | * @param int $max_cat |
||
| 619 | * @return array |
||
| 620 | * @throws Exception |
||
| 621 | */ |
||
| 622 | public function getSegmentExplorer($bounds, $activity_type = 'riding', $min_cat = null, $max_cat = null) { |
||
| 629 | |||
| 630 | /** |
||
| 631 | * List efforts filtered by athlete and/or a date range |
||
| 632 | * |
||
| 633 | * @link http://strava.github.io/api/v3/segments/#efforts |
||
| 634 | * @param int $id |
||
| 635 | * @param int $athlete_id |
||
| 636 | * @param string $start_date_local |
||
| 637 | * @param string $end_date_local |
||
| 638 | * @param int $page |
||
| 639 | * @param int $per_page |
||
| 640 | * @return array |
||
| 641 | * @throws Exception |
||
| 642 | 2 | */ |
|
| 643 | public function getSegmentEffort($id, $athlete_id = null, $start_date_local = null, $end_date_local = null, $page = null, $per_page = null) { |
||
| 650 | |||
| 651 | /** |
||
| 652 | * Retrieve activity streams |
||
| 653 | * |
||
| 654 | * @link http://strava.github.io/api/v3/streams/#activity |
||
| 655 | * @param int $id |
||
| 656 | * @param string $types |
||
| 657 | * @param string $resolution |
||
| 658 | * @param string $series_type |
||
| 659 | * @return array |
||
| 660 | * @throws Exception |
||
| 661 | 2 | */ |
|
| 662 | public function getStreamsActivity($id, $types, $resolution = null, $series_type = 'distance') { |
||
| 669 | |||
| 670 | /** |
||
| 671 | * Retrieve effort streams |
||
| 672 | * |
||
| 673 | * @link http://strava.github.io/api/v3/streams/#effort |
||
| 674 | * @param int $id |
||
| 675 | * @param string $types |
||
| 676 | * @param string $resolution |
||
| 677 | * @param string $series_type |
||
| 678 | * @return array |
||
| 679 | 2 | * @throws Exception |
|
| 680 | */ |
||
| 681 | 2 | public function getStreamsEffort($id, $types, $resolution = null, $series_type = 'distance') { |
|
| 688 | |||
| 689 | /** |
||
| 690 | * Retrieve segment streams |
||
| 691 | * @link http://strava.github.io/api/v3/streams/#segment |
||
| 692 | * @param int $id |
||
| 693 | * @param string $types |
||
| 694 | * @param string $resolution |
||
| 695 | * @param string $series_type |
||
| 696 | * @return array |
||
| 697 | * @throws Exception |
||
| 698 | */ |
||
| 699 | public function getStreamsSegment($id, $types, $resolution = null, $series_type = 'distance') { |
||
| 706 | } |
||
| 707 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.