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 |
||
15 | class Client |
||
16 | { |
||
17 | /** |
||
18 | * @var ServiceInterface $service |
||
19 | */ |
||
20 | protected $service; |
||
21 | |||
22 | /** |
||
23 | * Initiate this class with a subclass of ServiceInterface. There are two |
||
24 | * service subclasses available: |
||
25 | * - Service\REST: Service which makes calls to the live Strava API |
||
26 | * - Service\Stub: Service stub for test purposes (unit tests) |
||
27 | * |
||
28 | * @param ServiceInterface $service |
||
29 | */ |
||
30 | 79 | public function __construct(ServiceInterface $service) |
|
31 | { |
||
32 | 79 | $this->service = $service; |
|
33 | 79 | } |
|
34 | |||
35 | /** |
||
36 | * Retrieve current athlete |
||
37 | * |
||
38 | * @link https://strava.github.io/api/v3/athlete/#get-details, |
||
39 | * https://strava.github.io/api/v3/athlete/#get-another-details |
||
40 | * @param int $id |
||
41 | * @return array |
||
42 | * @throws Exception |
||
43 | */ |
||
44 | 2 | public function getAthlete($id = null) |
|
45 | { |
||
46 | try { |
||
47 | 2 | return $this->service->getAthlete($id); |
|
48 | 1 | } catch (ServiceException $e) { |
|
49 | 1 | throw new ClientException('[SERVICE] ' . $e->getMessage()); |
|
50 | } |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Retrieve athlete stats |
||
55 | * |
||
56 | * Only available for the authenticated athlete. |
||
57 | * |
||
58 | * @link https://strava.github.io/api/v3/athlete/#stats |
||
59 | * @param int $id |
||
60 | * @return array |
||
61 | * @throws ClientException |
||
62 | */ |
||
63 | 1 | public function getAthleteStats($id) |
|
64 | { |
||
65 | try { |
||
66 | 1 | return $this->service->getAthleteStats($id); |
|
67 | } catch (ServiceException $e) { |
||
68 | throw new ClientException('[SERVICE] ' . $e->getMessage()); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Retrieve athlete routes |
||
74 | * |
||
75 | * @link https://strava.github.io/api/v3/routes/#list |
||
76 | * @param int $id |
||
77 | * @return array |
||
78 | * @throws ClientException |
||
79 | */ |
||
80 | 1 | public function getAthleteRoutes($id, $type = null, $after = null, $page = null, $per_page = null) |
|
81 | { |
||
82 | try { |
||
83 | 1 | return $this->service->getAthleteRoutes($id, $type, $after, $page, $per_page); |
|
84 | } catch (ServiceException $e) { |
||
85 | throw new ClientException('[SERVICE] ' . $e->getMessage()); |
||
86 | } |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * List athlete clubs |
||
91 | * |
||
92 | * @link https://strava.github.io/api/v3/clubs/#get-athletes |
||
93 | * @return array |
||
94 | * @throws Exception |
||
95 | */ |
||
96 | 2 | public function getAthleteClubs() |
|
97 | { |
||
98 | try { |
||
99 | 2 | return $this->service->getAthleteClubs(); |
|
100 | 1 | } catch (ServiceException $e) { |
|
101 | 1 | throw new ClientException('[SERVICE] ' . $e->getMessage()); |
|
102 | } |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * List athlete activities |
||
107 | * |
||
108 | * @link https://strava.github.io/api/v3/activities/#get-activities |
||
109 | * @param string $before |
||
110 | * @param string $after |
||
111 | * @param int $page |
||
112 | * @param int $per_page |
||
113 | * @return array |
||
114 | * @throws Exception |
||
115 | */ |
||
116 | 2 | public function getAthleteActivities($before = null, $after = null, $page = null, $per_page = null) |
|
117 | { |
||
118 | try { |
||
119 | 2 | return $this->service->getAthleteActivities($before, $after, $page, $per_page); |
|
120 | 1 | } catch (ServiceException $e) { |
|
121 | 1 | throw new ClientException('[SERVICE] ' . $e->getMessage()); |
|
122 | } |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * List athlete friends |
||
127 | * |
||
128 | * @link https://strava.github.io/api/v3/follow/#friends |
||
129 | * @param int $id |
||
130 | * @param int $page |
||
131 | * @param int $per_page |
||
132 | * @return array |
||
133 | * @throws Exception |
||
134 | */ |
||
135 | 2 | public function getAthleteFriends($id = null, $page = null, $per_page = null) |
|
136 | { |
||
137 | try { |
||
138 | 2 | return $this->service->getAthleteFriends($id, $page, $per_page); |
|
139 | 1 | } catch (ServiceException $e) { |
|
140 | 1 | throw new ClientException('[SERVICE] ' . $e->getMessage()); |
|
141 | } |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * List athlete followers |
||
146 | * |
||
147 | * @link https://strava.github.io/api/v3/follow/#followers |
||
148 | * @param int $id |
||
149 | * @param int $page |
||
150 | * @param int $per_page |
||
151 | * @return array |
||
152 | * @throws Exception |
||
153 | */ |
||
154 | 2 | public function getAthleteFollowers($id = null, $page = null, $per_page = null) |
|
155 | { |
||
156 | try { |
||
157 | 2 | return $this->service->getAthleteFollowers($id, $page, $per_page); |
|
158 | 1 | } catch (ServiceException $e) { |
|
159 | 1 | throw new ClientException('[SERVICE] ' . $e->getMessage()); |
|
160 | } |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * List both following |
||
165 | * |
||
166 | * @link https://strava.github.io/api/v3/follow/#both |
||
167 | * @param int $id |
||
168 | * @param int $page |
||
169 | * @param int $per_page |
||
170 | * @return array |
||
171 | * @throws Exception |
||
172 | */ |
||
173 | 2 | public function getAthleteBothFollowing($id, $page = null, $per_page = null) |
|
174 | { |
||
175 | try { |
||
176 | 2 | return $this->service->getAthleteBothFollowing($id, $page, $per_page); |
|
177 | 1 | } catch (ServiceException $e) { |
|
178 | 1 | throw new ClientException('[SERVICE] ' . $e->getMessage()); |
|
179 | } |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * List athlete K/QOMs/CRs |
||
184 | * |
||
185 | * @link https://strava.github.io/api/v3/athlete/#koms |
||
186 | * @param int $id |
||
187 | * @param int $page |
||
188 | * @param int $per_page |
||
189 | * @return array |
||
190 | * @throws Exception |
||
191 | */ |
||
192 | 2 | public function getAthleteKom($id, $page = null, $per_page = null) |
|
193 | { |
||
194 | try { |
||
195 | 2 | return $this->service->getAthleteKom($id, $page, $per_page); |
|
196 | 1 | } catch (ServiceException $e) { |
|
197 | 1 | throw new ClientException('[SERVICE] ' . $e->getMessage()); |
|
198 | } |
||
199 | } |
||
200 | |||
201 | /** |
||
202 | * List athlete zones |
||
203 | * |
||
204 | * @link https://strava.github.io/api/v3/athlete/#zones |
||
205 | * @return array |
||
206 | * @throws Exception |
||
207 | */ |
||
208 | 2 | public function getAthleteZones() |
|
209 | { |
||
210 | try { |
||
211 | 2 | return $this->service->getAthleteZones(); |
|
212 | 1 | } catch (ServiceException $e) { |
|
213 | 1 | throw new ClientException('[SERVICE] ' . $e->getMessage()); |
|
214 | } |
||
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 an activity |
||
260 | * |
||
261 | * @link https://strava.github.io/api/v3/athlete/#get-details, |
||
262 | * https://strava.github.io/api/v3/athlete/#get-another-details |
||
263 | * @param int $id |
||
264 | * @param boolean $include_all_efforts |
||
265 | * @return array |
||
266 | * @throws Exception |
||
267 | */ |
||
268 | 2 | public function getActivity($id, $include_all_efforts = null) |
|
276 | |||
277 | /** |
||
278 | * List activity comments |
||
279 | * |
||
280 | * @link https://strava.github.io/api/v3/comments/#list |
||
281 | * @param int $id |
||
282 | * @param boolean $markdown |
||
283 | * @param int $page |
||
284 | * @param int $per_page |
||
285 | * @return array |
||
286 | * @throws Exception |
||
287 | */ |
||
288 | 2 | public function getActivityComments($id, $markdown = null, $page = null, $per_page = null) |
|
296 | |||
297 | /** |
||
298 | * List activity kudoers |
||
299 | * |
||
300 | * @link https://strava.github.io/api/v3/kudos/#list |
||
301 | * @param int $id |
||
302 | * @param int $page |
||
303 | * @param int $per_page |
||
304 | * @return array |
||
305 | * @throws Exception |
||
306 | */ |
||
307 | 2 | public function getActivityKudos($id, $page = null, $per_page = null) |
|
315 | |||
316 | /** |
||
317 | * List activity photos |
||
318 | * |
||
319 | * @link https://strava.github.io/api/v3/photos/#list |
||
320 | * @param int $id |
||
321 | * @param int $size In pixels. |
||
322 | * @param string $photo_sources Must be "true". |
||
323 | * @return array |
||
324 | * @throws Exception |
||
325 | */ |
||
326 | 2 | public function getActivityPhotos($id, $size = 2048, $photo_sources = 'true') |
|
334 | |||
335 | /** |
||
336 | * List activity zones |
||
337 | * |
||
338 | * @link https://strava.github.io/api/v3/activities/#zones |
||
339 | * @param int $id |
||
340 | * @return array |
||
341 | * @throws Exception |
||
342 | */ |
||
343 | 2 | public function getActivityZones($id) |
|
351 | |||
352 | /** |
||
353 | * List activity laps |
||
354 | * |
||
355 | * @link https://strava.github.io/api/v3/activities/#laps |
||
356 | * @param int $id |
||
357 | * @return array |
||
358 | * @throws Exception |
||
359 | */ |
||
360 | 2 | public function getActivityLaps($id) |
|
368 | |||
369 | /** |
||
370 | * Check upload status |
||
371 | * |
||
372 | * @link https://strava.github.io/api/v3/uploads/#get-status |
||
373 | * @param int $id |
||
374 | * @return array |
||
375 | * @throws Exception |
||
376 | */ |
||
377 | 2 | public function getActivityUploadStatus($id) |
|
385 | |||
386 | /** |
||
387 | * Create an activity |
||
388 | * |
||
389 | * @link https://strava.github.io/api/v3/activities/#create |
||
390 | * @param string $name |
||
391 | * @param string $type |
||
392 | * @param string $start_date_local |
||
393 | * @param int $elapsed_time |
||
394 | * @param string $description |
||
395 | * @param float $distance |
||
396 | * @param int $private |
||
397 | * @param int $trainer |
||
398 | * @return array |
||
399 | * @throws Exception |
||
400 | */ |
||
401 | 2 | public function createActivity($name, $type, $start_date_local, $elapsed_time, $description = null, $distance = null, $private = null, $trainer = null) |
|
409 | |||
410 | /** |
||
411 | * Upload an activity |
||
412 | * |
||
413 | * @link https://strava.github.io/api/v3/uploads/#post-file |
||
414 | * @param mixed $file |
||
415 | * @param string $activity_type |
||
416 | * @param string $name |
||
417 | * @param string $description |
||
418 | * @param int $private |
||
419 | * @param int $trainer |
||
420 | * @param int $commute |
||
421 | * @param string $data_type |
||
422 | * @param string $external_id |
||
423 | * @return array |
||
424 | * @throws Exception |
||
425 | */ |
||
426 | 2 | public function uploadActivity($file, $activity_type = null, $name = null, $description = null, $private = null, $trainer = null, $commute = null, $data_type = null, $external_id = null) |
|
434 | |||
435 | /** |
||
436 | * Update an activity |
||
437 | * |
||
438 | * @link https://strava.github.io/api/v3/activities/#put-updates |
||
439 | * @param int $id |
||
440 | * @param string $name |
||
441 | * @param string $type |
||
442 | * @param boolean $private |
||
443 | * @param boolean $commute |
||
444 | * @param boolean $trainer |
||
445 | * @param string $gear_id |
||
446 | * @param string $description |
||
447 | * @return array |
||
448 | * @throws Exception |
||
449 | */ |
||
450 | 2 | public function updateActivity($id, $name = null, $type = null, $private = false, $commute = false, $trainer = false, $gear_id = null, $description = null) |
|
458 | |||
459 | /** |
||
460 | * Delete an activity |
||
461 | * |
||
462 | * @link https://strava.github.io/api/v3/activities/#delete |
||
463 | * @param int $id |
||
464 | * @return array |
||
465 | * @throws Exception |
||
466 | */ |
||
467 | 2 | public function deleteActivity($id) |
|
475 | |||
476 | /** |
||
477 | * Retrieve gear |
||
478 | * |
||
479 | * @link https://strava.github.io/api/v3/gear/ |
||
480 | * @param int $id |
||
481 | * @return array |
||
482 | * @throws Exception |
||
483 | */ |
||
484 | 2 | public function getGear($id) |
|
492 | |||
493 | /** |
||
494 | * Retrieve a club |
||
495 | * |
||
496 | * @link https://strava.github.io/api/v3/clubs/#get-details |
||
497 | * @param int $id |
||
498 | * @return array |
||
499 | * @throws Exception |
||
500 | */ |
||
501 | 2 | public function getClub($id) |
|
509 | |||
510 | /** |
||
511 | * List club members |
||
512 | * |
||
513 | * @link https://strava.github.io/api/v3/clubs/#get-members |
||
514 | * @param int $id |
||
515 | * @param int $page |
||
516 | * @param int $per_page |
||
517 | * @return array |
||
518 | * @throws Exception |
||
519 | */ |
||
520 | 2 | public function getClubMembers($id, $page = null, $per_page = null) |
|
528 | |||
529 | /** |
||
530 | * List club activities |
||
531 | * |
||
532 | * @link https://strava.github.io/api/v3/clubs/#get-activities |
||
533 | * @param int $id |
||
534 | * @param int $page |
||
535 | * @param int $per_page |
||
536 | * @return array |
||
537 | * @throws Exception |
||
538 | */ |
||
539 | 2 | public function getClubActivities($id, $page = null, $per_page = null) |
|
547 | |||
548 | /** |
||
549 | * List club announcements |
||
550 | * |
||
551 | * @link https://strava.github.io/api/v3/clubs/#get-announcements |
||
552 | * @param int $id |
||
553 | * @return array |
||
554 | * @throws Exception |
||
555 | */ |
||
556 | 2 | public function getClubAnnouncements($id) |
|
564 | |||
565 | /** |
||
566 | * List club group events |
||
567 | * |
||
568 | * @link https://strava.github.io/api/v3/clubs/#get-group-events |
||
569 | * @param int $id |
||
570 | * @return array |
||
571 | * @throws Exception |
||
572 | */ |
||
573 | 2 | public function getClubGroupEvents($id) |
|
581 | |||
582 | /** |
||
583 | * Join a club |
||
584 | * |
||
585 | * @link https://strava.github.io/api/v3/clubs/#join |
||
586 | * @param int $id |
||
587 | * @return array |
||
588 | * @throws Exception |
||
589 | */ |
||
590 | 2 | public function joinClub($id) |
|
598 | |||
599 | /** |
||
600 | * Leave a club |
||
601 | * |
||
602 | * @link https://strava.github.io/api/v3/clubs/#leave |
||
603 | * @param int $id |
||
604 | * @return array |
||
605 | * @throws Exception |
||
606 | */ |
||
607 | 2 | public function leaveClub($id) |
|
615 | |||
616 | /** |
||
617 | * Get route details |
||
618 | * |
||
619 | * @link https://strava.github.io/api/v3/routes/#list |
||
620 | * @param int $id |
||
621 | * @return array |
||
622 | * @throws Exception |
||
623 | */ |
||
624 | 2 | public function getRoute($id) |
|
632 | |||
633 | /** |
||
634 | * Get route as GPX. |
||
635 | * |
||
636 | * @link https://developers.strava.com/docs/reference/#api-Routes-getRouteAsGPX |
||
637 | * @param int $id |
||
638 | * @return string |
||
639 | * @throws Exception |
||
640 | */ |
||
641 | public function getRouteAsGPX($id) |
||
649 | |||
650 | /** |
||
651 | * Get route as TCX. |
||
652 | * |
||
653 | * @link https://developers.strava.com/docs/reference/#api-Routes-getRouteAsTCX |
||
654 | * @param int $id |
||
655 | * @return string |
||
656 | * @throws Exception |
||
657 | */ |
||
658 | public function getRouteAsTCX($id) |
||
666 | |||
667 | /** |
||
668 | * Retrieve a segment |
||
669 | * |
||
670 | * @link https://strava.github.io/api/v3/segments/#retrieve |
||
671 | * @param int $id |
||
672 | * @return array |
||
673 | * @throws Exception |
||
674 | */ |
||
675 | 2 | public function getSegment($id) |
|
683 | |||
684 | /** |
||
685 | * Segment leaderboards |
||
686 | * |
||
687 | * @link https://strava.github.io/api/v3/segments/#leaderboard |
||
688 | * @param int $id |
||
689 | * @param string $gender |
||
690 | * @param string $age_group |
||
691 | * @param string $weight_class |
||
692 | * @param boolean $following |
||
693 | * @param int $club_id |
||
694 | * @param string $date_range |
||
695 | * @param int $context_entries |
||
696 | * @param int $page |
||
697 | * @param int $per_page |
||
698 | * @return array |
||
699 | * @throws Exception |
||
700 | */ |
||
701 | 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) |
|
709 | |||
710 | /** |
||
711 | * Segment explorer |
||
712 | * |
||
713 | * @link https://strava.github.io/api/v3/segments/#explore |
||
714 | * @param string $bounds |
||
715 | * @param string $activity_type |
||
716 | * @param int $min_cat |
||
717 | * @param int $max_cat |
||
718 | * @return array |
||
719 | * @throws Exception |
||
720 | */ |
||
721 | 2 | public function getSegmentExplorer($bounds, $activity_type = 'riding', $min_cat = null, $max_cat = null) |
|
729 | |||
730 | /** |
||
731 | * List efforts filtered by athlete and/or a date range |
||
732 | * |
||
733 | * @link https://strava.github.io/api/v3/segments/#efforts |
||
734 | * @param int $id |
||
735 | * @param int $athlete_id |
||
736 | * @param string $start_date_local |
||
737 | * @param string $end_date_local |
||
738 | * @param int $page |
||
739 | * @param int $per_page |
||
740 | * @return array |
||
741 | * @throws Exception |
||
742 | */ |
||
743 | 2 | public function getSegmentEffort($id, $athlete_id = null, $start_date_local = null, $end_date_local = null, $page = null, $per_page = null) |
|
751 | |||
752 | /** |
||
753 | * Retrieve activity streams |
||
754 | * |
||
755 | * @link https://strava.github.io/api/v3/streams/#activity |
||
756 | * @param int $id |
||
757 | * @param string $types |
||
758 | * @param string $resolution |
||
759 | * @param string $series_type |
||
760 | * @return array |
||
761 | * @throws Exception |
||
762 | */ |
||
763 | 2 | public function getStreamsActivity($id, $types, $resolution = null, $series_type = 'distance') |
|
771 | |||
772 | /** |
||
773 | * Retrieve effort streams |
||
774 | * |
||
775 | * @link https://strava.github.io/api/v3/streams/#effort |
||
776 | * @param int $id |
||
777 | * @param string $types |
||
778 | * @param string $resolution |
||
779 | * @param string $series_type |
||
780 | * @return array |
||
781 | * @throws Exception |
||
782 | */ |
||
783 | 2 | public function getStreamsEffort($id, $types, $resolution = null, $series_type = 'distance') |
|
791 | |||
792 | /** |
||
793 | * Retrieve segment streams |
||
794 | * @link https://strava.github.io/api/v3/streams/#segment |
||
795 | * @param int $id |
||
796 | * @param string $types |
||
797 | * @param string $resolution |
||
798 | * @param string $series_type |
||
799 | * @return array |
||
800 | * @throws Exception |
||
801 | */ |
||
802 | 2 | public function getStreamsSegment($id, $types, $resolution = null, $series_type = 'distance') |
|
810 | |||
811 | /** |
||
812 | * Retrieve route streams |
||
813 | * |
||
814 | * @link https://strava.github.io/api/v3/streams/#routes |
||
815 | * @param int $id |
||
816 | * @return array |
||
817 | * @throws Exception |
||
818 | */ |
||
819 | 2 | public function getStreamsRoute($id) |
|
827 | } |
||
828 |
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.