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 | 76 | public function __construct(ServiceInterface $service) |
|
33 | |||
34 | /** |
||
35 | * Retrieve current athlete |
||
36 | * |
||
37 | * @link https://strava.github.io/api/v3/athlete/#get-details, |
||
38 | * https://strava.github.io/api/v3/athlete/#get-another-details |
||
39 | * @param int $id |
||
40 | * @return array |
||
41 | * @throws Exception |
||
42 | */ |
||
43 | 2 | public function getAthlete($id = null) |
|
51 | |||
52 | /** |
||
53 | * Retrieve athlete stats |
||
54 | * |
||
55 | * Only available for the authenticated athlete. |
||
56 | * |
||
57 | * @link https://strava.github.io/api/v3/athlete/#stats |
||
58 | * @param int $id |
||
59 | * @return array |
||
60 | * @throws ClientException |
||
61 | */ |
||
62 | 1 | public function getAthleteStats($id) |
|
70 | |||
71 | /** |
||
72 | * Retrieve athlete routes |
||
73 | * |
||
74 | * @link https://strava.github.io/api/v3/athlete/#stats |
||
75 | * @param int $id |
||
76 | * @return array |
||
77 | * @throws ClientException |
||
78 | */ |
||
79 | public function getAthleteRoutes($id) |
||
87 | |||
88 | /** |
||
89 | * List athlete clubs |
||
90 | * |
||
91 | * @link https://strava.github.io/api/v3/clubs/#get-athletes |
||
92 | * @return array |
||
93 | * @throws Exception |
||
94 | */ |
||
95 | 2 | public function getAthleteClubs() |
|
103 | |||
104 | /** |
||
105 | * List athlete activities |
||
106 | * |
||
107 | * @link https://strava.github.io/api/v3/activities/#get-activities |
||
108 | * @param string $before |
||
109 | * @param string $after |
||
110 | * @param int $page |
||
111 | * @param int $per_page |
||
112 | * @return array |
||
113 | * @throws Exception |
||
114 | */ |
||
115 | 2 | public function getAthleteActivities($before = null, $after = null, $page = null, $per_page = null) |
|
123 | |||
124 | /** |
||
125 | * List athlete friends |
||
126 | * |
||
127 | * @link https://strava.github.io/api/v3/follow/#friends |
||
128 | * @param int $id |
||
129 | * @param int $page |
||
130 | * @param int $per_page |
||
131 | * @return array |
||
132 | * @throws Exception |
||
133 | */ |
||
134 | 2 | public function getAthleteFriends($id = null, $page = null, $per_page = null) |
|
142 | |||
143 | /** |
||
144 | * List athlete followers |
||
145 | * |
||
146 | * @link https://strava.github.io/api/v3/follow/#followers |
||
147 | * @param int $id |
||
148 | * @param int $page |
||
149 | * @param int $per_page |
||
150 | * @return array |
||
151 | * @throws Exception |
||
152 | */ |
||
153 | 2 | public function getAthleteFollowers($id = null, $page = null, $per_page = null) |
|
161 | |||
162 | /** |
||
163 | * List both following |
||
164 | * |
||
165 | * @link https://strava.github.io/api/v3/follow/#both |
||
166 | * @param int $id |
||
167 | * @param int $page |
||
168 | * @param int $per_page |
||
169 | * @return array |
||
170 | * @throws Exception |
||
171 | */ |
||
172 | 2 | public function getAthleteBothFollowing($id, $page = null, $per_page = null) |
|
180 | |||
181 | /** |
||
182 | * List athlete K/QOMs/CRs |
||
183 | * |
||
184 | * @link https://strava.github.io/api/v3/athlete/#koms |
||
185 | * @param int $id |
||
186 | * @param int $page |
||
187 | * @param int $per_page |
||
188 | * @return array |
||
189 | * @throws Exception |
||
190 | */ |
||
191 | 2 | public function getAthleteKom($id, $page = null, $per_page = null) |
|
199 | |||
200 | /** |
||
201 | * List athlete zones |
||
202 | * |
||
203 | * @link https://strava.github.io/api/v3/athlete/#zones |
||
204 | * @return array |
||
205 | * @throws Exception |
||
206 | */ |
||
207 | 2 | public function getAthleteZones() |
|
215 | |||
216 | |||
217 | |||
218 | /** |
||
219 | * List starred segment |
||
220 | * |
||
221 | * @link https://strava.github.io/api/v3/segments/#starred |
||
222 | * @param int $id |
||
223 | * @param int $page |
||
224 | * @param int $per_page |
||
225 | * @return array |
||
226 | * @throws Exception |
||
227 | */ |
||
228 | 2 | public function getAthleteStarredSegments($id = null, $page = null, $per_page = null) |
|
236 | |||
237 | /** |
||
238 | * Update current athlete |
||
239 | * |
||
240 | * @link https://strava.github.io/api/v3/athlete/#update |
||
241 | * @param string $city |
||
242 | * @param string $state |
||
243 | * @param string $country |
||
244 | * @param string $sex |
||
245 | * @param float $weight |
||
246 | * @return array |
||
247 | * @throws Exception |
||
248 | */ |
||
249 | 2 | public function updateAthlete($city, $state, $country, $sex, $weight) |
|
257 | |||
258 | /** |
||
259 | * Retrieve activity from user followers |
||
260 | * |
||
261 | * @link https://strava.github.io/api/v3/activities/#get-feed |
||
262 | * |
||
263 | * @param type $before |
||
264 | * @param type $page |
||
265 | * @param type $per_page |
||
266 | * @return type |
||
267 | * @throws ClientException |
||
268 | */ |
||
269 | public function getActivityFollowing($before = null, $page = null, $per_page = null) |
||
277 | |||
278 | |||
279 | /** |
||
280 | * Retrieve an activity |
||
281 | * |
||
282 | * @link https://strava.github.io/api/v3/athlete/#get-details, |
||
283 | * https://strava.github.io/api/v3/athlete/#get-another-details |
||
284 | * @param int $id |
||
285 | * @param boolean $include_all_efforts |
||
286 | * @return array |
||
287 | * @throws Exception |
||
288 | */ |
||
289 | 2 | public function getActivity($id, $include_all_efforts = null) |
|
297 | |||
298 | /** |
||
299 | * List activity comments |
||
300 | * |
||
301 | * @link https://strava.github.io/api/v3/comments/#list |
||
302 | * @param int $id |
||
303 | * @param boolean $markdown |
||
304 | * @param int $page |
||
305 | * @param int $per_page |
||
306 | * @return array |
||
307 | * @throws Exception |
||
308 | */ |
||
309 | 2 | public function getActivityComments($id, $markdown = null, $page = null, $per_page = null) |
|
317 | |||
318 | /** |
||
319 | * List activity kudoers |
||
320 | * |
||
321 | * @link https://strava.github.io/api/v3/kudos/#list |
||
322 | * @param int $id |
||
323 | * @param int $page |
||
324 | * @param int $per_page |
||
325 | * @return array |
||
326 | * @throws Exception |
||
327 | */ |
||
328 | 2 | public function getActivityKudos($id, $page = null, $per_page = null) |
|
336 | |||
337 | /** |
||
338 | * List activity photos |
||
339 | * |
||
340 | * @link https://strava.github.io/api/v3/photos/#list |
||
341 | * @param int $id |
||
342 | * @param int $size In pixels. |
||
343 | * @param string $photo_sources Must be "true". |
||
344 | * @return array |
||
345 | * @throws Exception |
||
346 | */ |
||
347 | 2 | public function getActivityPhotos($id, $size = 2048, $photo_sources = 'true') |
|
355 | |||
356 | /** |
||
357 | * List activity zones |
||
358 | * |
||
359 | * @link https://strava.github.io/api/v3/activities/#zones |
||
360 | * @param int $id |
||
361 | * @return array |
||
362 | * @throws Exception |
||
363 | */ |
||
364 | 2 | public function getActivityZones($id) |
|
372 | |||
373 | /** |
||
374 | * List activity laps |
||
375 | * |
||
376 | * @link https://strava.github.io/api/v3/activities/#laps |
||
377 | * @param int $id |
||
378 | * @return array |
||
379 | * @throws Exception |
||
380 | */ |
||
381 | 2 | public function getActivityLaps($id) |
|
389 | |||
390 | /** |
||
391 | * Check upload status |
||
392 | * |
||
393 | * @link https://strava.github.io/api/v3/uploads/#get-status |
||
394 | * @param int $id |
||
395 | * @return array |
||
396 | * @throws Exception |
||
397 | */ |
||
398 | 2 | public function getActivityUploadStatus($id) |
|
406 | |||
407 | /** |
||
408 | * Create an activity |
||
409 | * |
||
410 | * @link https://strava.github.io/api/v3/activities/#create |
||
411 | * @param string $name |
||
412 | * @param string $type |
||
413 | * @param string $start_date_local |
||
414 | * @param int $elapsed_time |
||
415 | * @param string $description |
||
416 | * @param float $distance |
||
417 | * @param int $private |
||
418 | * @param int $trainer |
||
419 | * @return array |
||
420 | * @throws Exception |
||
421 | */ |
||
422 | 2 | public function createActivity($name, $type, $start_date_local, $elapsed_time, $description = null, $distance = null, $private = null, $trainer = null) |
|
430 | |||
431 | /** |
||
432 | * Upload an activity |
||
433 | * |
||
434 | * @link https://strava.github.io/api/v3/uploads/#post-file |
||
435 | * @param mixed $file |
||
436 | * @param string $activity_type |
||
437 | * @param string $name |
||
438 | * @param string $description |
||
439 | * @param int $private |
||
440 | * @param int $trainer |
||
441 | * @param int $commute |
||
442 | * @param string $data_type |
||
443 | * @param string $external_id |
||
444 | * @return array |
||
445 | * @throws Exception |
||
446 | */ |
||
447 | 2 | public function uploadActivity($file, $activity_type = null, $name = null, $description = null, $private = null, $trainer = null, $commute = null, $data_type = null, $external_id = null) |
|
455 | |||
456 | /** |
||
457 | * Update an activity |
||
458 | * |
||
459 | * @link https://strava.github.io/api/v3/activities/#put-updates |
||
460 | * @param int $id |
||
461 | * @param string $name |
||
462 | * @param string $type |
||
463 | * @param boolean $private |
||
464 | * @param boolean $commute |
||
465 | * @param boolean $trainer |
||
466 | * @param string $gear_id |
||
467 | * @param string $description |
||
468 | * @return array |
||
469 | * @throws Exception |
||
470 | */ |
||
471 | 2 | public function updateActivity($id, $name = null, $type = null, $private = false, $commute = false, $trainer = false, $gear_id = null, $description = null) |
|
479 | |||
480 | /** |
||
481 | * Delete an activity |
||
482 | * |
||
483 | * @link https://strava.github.io/api/v3/activities/#delete |
||
484 | * @param int $id |
||
485 | * @return array |
||
486 | * @throws Exception |
||
487 | */ |
||
488 | 2 | public function deleteActivity($id) |
|
496 | |||
497 | /** |
||
498 | * Retrieve gear |
||
499 | * |
||
500 | * @link https://strava.github.io/api/v3/gear/ |
||
501 | * @param int $id |
||
502 | * @return array |
||
503 | * @throws Exception |
||
504 | */ |
||
505 | 2 | public function getGear($id) |
|
513 | |||
514 | /** |
||
515 | * Retrieve a club |
||
516 | * |
||
517 | * @link https://strava.github.io/api/v3/clubs/#get-details |
||
518 | * @param int $id |
||
519 | * @return array |
||
520 | * @throws Exception |
||
521 | */ |
||
522 | 2 | public function getClub($id) |
|
530 | |||
531 | /** |
||
532 | * List club members |
||
533 | * |
||
534 | * @link https://strava.github.io/api/v3/clubs/#get-members |
||
535 | * @param int $id |
||
536 | * @param int $page |
||
537 | * @param int $per_page |
||
538 | * @return array |
||
539 | * @throws Exception |
||
540 | */ |
||
541 | 2 | public function getClubMembers($id, $page = null, $per_page = null) |
|
549 | |||
550 | /** |
||
551 | * List club activities |
||
552 | * |
||
553 | * @link https://strava.github.io/api/v3/clubs/#get-activities |
||
554 | * @param int $id |
||
555 | * @param int $page |
||
556 | * @param int $per_page |
||
557 | * @return array |
||
558 | * @throws Exception |
||
559 | */ |
||
560 | 2 | public function getClubActivities($id, $page = null, $per_page = null) |
|
568 | |||
569 | /** |
||
570 | * List club announcements |
||
571 | * |
||
572 | * @link https://strava.github.io/api/v3/clubs/#get-announcements |
||
573 | * @param int $id |
||
574 | * @return array |
||
575 | * @throws Exception |
||
576 | */ |
||
577 | 2 | public function getClubAnnouncements($id) |
|
585 | |||
586 | /** |
||
587 | * List club group events |
||
588 | * |
||
589 | * @link https://strava.github.io/api/v3/clubs/#get-group-events |
||
590 | * @param int $id |
||
591 | * @return array |
||
592 | * @throws Exception |
||
593 | */ |
||
594 | 2 | public function getClubGroupEvents($id) |
|
602 | |||
603 | /** |
||
604 | * Join a club |
||
605 | * |
||
606 | * @link https://strava.github.io/api/v3/clubs/#join |
||
607 | * @param int $id |
||
608 | * @return array |
||
609 | * @throws Exception |
||
610 | */ |
||
611 | 2 | public function joinClub($id) |
|
619 | |||
620 | /** |
||
621 | * Leave a club |
||
622 | * |
||
623 | * @link https://strava.github.io/api/v3/clubs/#leave |
||
624 | * @param int $id |
||
625 | * @return array |
||
626 | * @throws Exception |
||
627 | */ |
||
628 | 2 | public function leaveClub($id) |
|
636 | |||
637 | /** |
||
638 | * Retrieve a segment |
||
639 | * |
||
640 | * @link https://strava.github.io/api/v3/segments/#retrieve |
||
641 | * @param int $id |
||
642 | * @return array |
||
643 | * @throws Exception |
||
644 | */ |
||
645 | 2 | public function getSegment($id) |
|
653 | |||
654 | /** |
||
655 | * Segment leaderboards |
||
656 | * |
||
657 | * @link https://strava.github.io/api/v3/segments/#leaderboard |
||
658 | * @param int $id |
||
659 | * @param string $gender |
||
660 | * @param string $age_group |
||
661 | * @param string $weight_class |
||
662 | * @param boolean $following |
||
663 | * @param int $club_id |
||
664 | * @param string $date_range |
||
665 | * @param int $context_entries |
||
666 | * @param int $page |
||
667 | * @param int $per_page |
||
668 | * @return array |
||
669 | * @throws Exception |
||
670 | */ |
||
671 | 2 | 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) |
|
679 | |||
680 | /** |
||
681 | * Segment explorer |
||
682 | * |
||
683 | * @link https://strava.github.io/api/v3/segments/#explore |
||
684 | * @param string $bounds |
||
685 | * @param string $activity_type |
||
686 | * @param int $min_cat |
||
687 | * @param int $max_cat |
||
688 | * @return array |
||
689 | * @throws Exception |
||
690 | */ |
||
691 | 2 | public function getSegmentExplorer($bounds, $activity_type = 'riding', $min_cat = null, $max_cat = null) |
|
699 | |||
700 | /** |
||
701 | * List efforts filtered by athlete and/or a date range |
||
702 | * |
||
703 | * @link https://strava.github.io/api/v3/segments/#efforts |
||
704 | * @param int $id |
||
705 | * @param int $athlete_id |
||
706 | * @param string $start_date_local |
||
707 | * @param string $end_date_local |
||
708 | * @param int $page |
||
709 | * @param int $per_page |
||
710 | * @return array |
||
711 | * @throws Exception |
||
712 | */ |
||
713 | 2 | public function getSegmentEffort($id, $athlete_id = null, $start_date_local = null, $end_date_local = null, $page = null, $per_page = null) |
|
721 | |||
722 | /** |
||
723 | * Retrieve activity streams |
||
724 | * |
||
725 | * @link https://strava.github.io/api/v3/streams/#activity |
||
726 | * @param int $id |
||
727 | * @param string $types |
||
728 | * @param string $resolution |
||
729 | * @param string $series_type |
||
730 | * @return array |
||
731 | * @throws Exception |
||
732 | */ |
||
733 | 2 | public function getStreamsActivity($id, $types, $resolution = null, $series_type = 'distance') |
|
741 | |||
742 | /** |
||
743 | * Retrieve effort streams |
||
744 | * |
||
745 | * @link https://strava.github.io/api/v3/streams/#effort |
||
746 | * @param int $id |
||
747 | * @param string $types |
||
748 | * @param string $resolution |
||
749 | * @param string $series_type |
||
750 | * @return array |
||
751 | * @throws Exception |
||
752 | */ |
||
753 | 2 | public function getStreamsEffort($id, $types, $resolution = null, $series_type = 'distance') |
|
761 | |||
762 | /** |
||
763 | * Retrieve segment streams |
||
764 | * @link https://strava.github.io/api/v3/streams/#segment |
||
765 | * @param int $id |
||
766 | * @param string $types |
||
767 | * @param string $resolution |
||
768 | * @param string $series_type |
||
769 | * @return array |
||
770 | * @throws Exception |
||
771 | */ |
||
772 | 2 | public function getStreamsSegment($id, $types, $resolution = null, $series_type = 'distance') |
|
780 | |||
781 | /** |
||
782 | * Retrieve route streams |
||
783 | * |
||
784 | * @link https://strava.github.io/api/v3/streams/#routes |
||
785 | * @param int $id |
||
786 | * @return array |
||
787 | * @throws Exception |
||
788 | */ |
||
789 | 2 | public function getStreamsRoute($id) |
|
797 | } |
||
798 |
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.