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) { |
|
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 an activity |
||
214 | * |
||
215 | * @link http://strava.github.io/api/v3/athlete/#get-details, |
||
216 | * http://strava.github.io/api/v3/athlete/#get-another-details |
||
217 | * @param int $id |
||
218 | * @param boolean $include_all_efforts |
||
219 | * @return array |
||
220 | * @throws Exception |
||
221 | */ |
||
222 | 2 | public function getActivity($id, $include_all_efforts = null) { |
|
229 | |||
230 | /** |
||
231 | * List activity comments |
||
232 | * |
||
233 | * @link http://strava.github.io/api/v3/comments/#list |
||
234 | * @param int $id |
||
235 | * @param boolean $markdown |
||
236 | * @param int $page |
||
237 | * @param int $per_page |
||
238 | * @return array |
||
239 | * @throws Exception |
||
240 | */ |
||
241 | 2 | public function getActivityComments($id, $markdown = null, $page = null, $per_page = null) { |
|
248 | |||
249 | /** |
||
250 | * List activity kudoers |
||
251 | * |
||
252 | * @link http://strava.github.io/api/v3/kudos/#list |
||
253 | * @param int $id |
||
254 | * @param int $page |
||
255 | * @param int $per_page |
||
256 | * @return array |
||
257 | * @throws Exception |
||
258 | */ |
||
259 | 2 | public function getActivityKudos($id, $page = null, $per_page = null) { |
|
266 | |||
267 | /** |
||
268 | * List activity photos |
||
269 | * |
||
270 | * @link http://strava.github.io/api/v3/photos/#list |
||
271 | * @param int $id |
||
272 | * @return array |
||
273 | * @throws Exception |
||
274 | */ |
||
275 | 2 | public function getActivityPhotos($id) { |
|
282 | |||
283 | /** |
||
284 | * List activity zones |
||
285 | * |
||
286 | * @link http://strava.github.io/api/v3/activities/#zones |
||
287 | * @param int $id |
||
288 | * @return array |
||
289 | * @throws Exception |
||
290 | */ |
||
291 | 2 | public function getActivityZones($id) { |
|
298 | |||
299 | /** |
||
300 | * List activity laps |
||
301 | * |
||
302 | * @link http://strava.github.io/api/v3/activities/#laps |
||
303 | * @param int $id |
||
304 | * @return array |
||
305 | * @throws Exception |
||
306 | */ |
||
307 | 2 | public function getActivityLaps($id) { |
|
314 | |||
315 | /** |
||
316 | * Check upload status |
||
317 | * |
||
318 | * @link http://strava.github.io/api/v3/uploads/#get-status |
||
319 | * @param int $id |
||
320 | * @return array |
||
321 | * @throws Exception |
||
322 | */ |
||
323 | 2 | public function getActivityUploadStatus($id) { |
|
330 | |||
331 | /** |
||
332 | * Create an activity |
||
333 | * |
||
334 | * @link http://strava.github.io/api/v3/activities/#create |
||
335 | * @param string $name |
||
336 | * @param string $type |
||
337 | * @param string $start_date_local |
||
338 | * @param int $elapsed_time |
||
339 | * @param string $description |
||
340 | * @param float $distance |
||
341 | * @return array |
||
342 | * @throws Exception |
||
343 | */ |
||
344 | 2 | public function createActivity($name, $type, $start_date_local, $elapsed_time, $description = null, $distance = null) { |
|
351 | |||
352 | /** |
||
353 | * Upload an activity |
||
354 | * |
||
355 | * @link http://strava.github.io/api/v3/uploads/#post-file |
||
356 | * @param mixed $file |
||
357 | * @param string $activity_type |
||
358 | * @param string $name |
||
359 | * @param string $description |
||
360 | * @param int $private |
||
361 | * @param int $trainer |
||
362 | * @param string $data_type |
||
363 | * @param string $external_id |
||
364 | * @return array |
||
365 | * @throws Exception |
||
366 | */ |
||
367 | 2 | public function uploadActivity($file, $activity_type = null, $name = null, $description = null, $private = null, $trainer = null, $data_type = null, $external_id = null) { |
|
374 | |||
375 | /** |
||
376 | * Update an activity |
||
377 | * |
||
378 | * @link http://strava.github.io/api/v3/activities/#put-updates |
||
379 | * @param int $id |
||
380 | * @param string $name |
||
381 | * @param string $type |
||
382 | * @param boolean $private |
||
383 | * @param boolean $commute |
||
384 | * @param boolean $trainer |
||
385 | * @param string $gear_id |
||
386 | * @param string $description |
||
387 | * @return array |
||
388 | * @throws Exception |
||
389 | */ |
||
390 | 2 | public function updateActivity($id, $name = null, $type = null, $private = false, $commute = false, $trainer = false, $gear_id = null, $description = null) { |
|
397 | |||
398 | /** |
||
399 | * Delete an activity |
||
400 | * |
||
401 | * @link http://strava.github.io/api/v3/activities/#delete |
||
402 | * @param int $id |
||
403 | * @return array |
||
404 | * @throws Exception |
||
405 | */ |
||
406 | 2 | public function deleteActivity($id) { |
|
413 | |||
414 | |||
415 | /** |
||
416 | * Retrieve gear |
||
417 | * |
||
418 | * @link http://strava.github.io/api/v3/gear/ |
||
419 | * @param int $id |
||
420 | * @return array |
||
421 | * @throws Exception |
||
422 | */ |
||
423 | 2 | public function getGear($id) { |
|
430 | |||
431 | /** |
||
432 | * Retrieve a club |
||
433 | * |
||
434 | * @link http://strava.github.io/api/v3/clubs/#get-details |
||
435 | * @param int $id |
||
436 | * @return array |
||
437 | * @throws Exception |
||
438 | */ |
||
439 | 2 | public function getClub($id) { |
|
446 | |||
447 | /** |
||
448 | * List club members |
||
449 | * |
||
450 | * @link http://strava.github.io/api/v3/clubs/#get-members |
||
451 | * @param int $id |
||
452 | * @param int $page |
||
453 | * @param int $per_page |
||
454 | * @return array |
||
455 | * @throws Exception |
||
456 | */ |
||
457 | 2 | public function getClubMembers($id, $page = null, $per_page = null) { |
|
464 | |||
465 | /** |
||
466 | * List club activities |
||
467 | * |
||
468 | * @link http://strava.github.io/api/v3/clubs/#get-activities |
||
469 | * @param int $id |
||
470 | * @param int $page |
||
471 | * @param int $per_page |
||
472 | * @return array |
||
473 | * @throws Exception |
||
474 | */ |
||
475 | 2 | public function getClubActivities($id, $page = null, $per_page = null) { |
|
482 | |||
483 | /** |
||
484 | * List club announcements |
||
485 | * |
||
486 | * @link https://strava.github.io/api/v3/clubs/#get-announcements |
||
487 | * @param int $id |
||
488 | * @return array |
||
489 | * @throws Exception |
||
490 | */ |
||
491 | 2 | public function getClubAnnouncements($id) { |
|
498 | |||
499 | /** |
||
500 | * List club group events |
||
501 | * |
||
502 | * @link https://strava.github.io/api/v3/clubs/#get-group-events |
||
503 | * @param int $id |
||
504 | * @return array |
||
505 | * @throws Exception |
||
506 | */ |
||
507 | 2 | public function getClubGroupEvents($id) { |
|
514 | |||
515 | /** |
||
516 | * Join a club |
||
517 | * |
||
518 | * @link https://strava.github.io/api/v3/clubs/#join |
||
519 | * @param int $id |
||
520 | * @return array |
||
521 | * @throws Exception |
||
522 | */ |
||
523 | 2 | public function joinClub($id) { |
|
530 | |||
531 | /** |
||
532 | * Leave a club |
||
533 | * |
||
534 | * @link https://strava.github.io/api/v3/clubs/#leave |
||
535 | * @param int $id |
||
536 | * @return array |
||
537 | * @throws Exception |
||
538 | */ |
||
539 | 2 | public function leaveClub($id) { |
|
546 | |||
547 | /** |
||
548 | * Retrieve a segment |
||
549 | * |
||
550 | * @link http://strava.github.io/api/v3/segments/#retrieve |
||
551 | * @param int $id |
||
552 | * @return array |
||
553 | * @throws Exception |
||
554 | */ |
||
555 | 2 | public function getSegment($id) { |
|
562 | |||
563 | /** |
||
564 | * Segment leaderboards |
||
565 | * |
||
566 | * @link http://strava.github.io/api/v3/segments/#leaderboard |
||
567 | * @param int $id |
||
568 | * @param string $gender |
||
569 | * @param string $age_group |
||
570 | * @param string $weight_class |
||
571 | * @param boolean $following |
||
572 | * @param int $club_id |
||
573 | * @param string $date_range |
||
574 | * @param int $page |
||
575 | * @param int $per_page |
||
576 | * @return array |
||
577 | * @throws Exception |
||
578 | */ |
||
579 | 2 | public function getSegmentLeaderboard($id, $gender = null, $age_group = null, $weight_class = null, $following = null, $club_id = null, $date_range = null, $page = null, $per_page = null) { |
|
586 | |||
587 | /** |
||
588 | * Segment explorer |
||
589 | * |
||
590 | * @link http://strava.github.io/api/v3/segments/#explore |
||
591 | * @param string $bounds |
||
592 | * @param string $activity_type |
||
593 | * @param int $min_cat |
||
594 | * @param int $max_cat |
||
595 | * @return array |
||
596 | * @throws Exception |
||
597 | */ |
||
598 | 2 | public function getSegmentExplorer($bounds, $activity_type = 'riding', $min_cat = null, $max_cat = null) { |
|
605 | |||
606 | /** |
||
607 | * List efforts filtered by athlete and/or a date range |
||
608 | * |
||
609 | * @link http://strava.github.io/api/v3/segments/#efforts |
||
610 | * @param int $id |
||
611 | * @param int $athlete_id |
||
612 | * @param string $start_date_local |
||
613 | * @param string $end_date_local |
||
614 | * @param int $page |
||
615 | * @param int $per_page |
||
616 | * @return array |
||
617 | * @throws Exception |
||
618 | */ |
||
619 | 2 | public function getSegmentEffort($id, $athlete_id = null, $start_date_local = null, $end_date_local = null, $page = null, $per_page = null) { |
|
626 | |||
627 | /** |
||
628 | * Retrieve activity streams |
||
629 | * |
||
630 | * @link http://strava.github.io/api/v3/streams/#activity |
||
631 | * @param int $id |
||
632 | * @param string $types |
||
633 | * @param string $resolution |
||
634 | * @param string $series_type |
||
635 | * @return array |
||
636 | * @throws Exception |
||
637 | */ |
||
638 | 2 | public function getStreamsActivity($id, $types, $resolution = 'all', $series_type = 'distance') { |
|
645 | |||
646 | /** |
||
647 | * Retrieve effort streams |
||
648 | * |
||
649 | * @link http://strava.github.io/api/v3/streams/#effort |
||
650 | * @param int $id |
||
651 | * @param string $types |
||
652 | * @param string $resolution |
||
653 | * @param string $series_type |
||
654 | * @return array |
||
655 | * @throws Exception |
||
656 | */ |
||
657 | 2 | public function getStreamsEffort($id, $types, $resolution = 'all', $series_type = 'distance') { |
|
664 | |||
665 | /** |
||
666 | * Retrieve segment streams |
||
667 | * @link http://strava.github.io/api/v3/streams/#segment |
||
668 | * @param int $id |
||
669 | * @param string $types |
||
670 | * @param string $resolution |
||
671 | * @param string $series_type |
||
672 | * @return array |
||
673 | * @throws Exception |
||
674 | */ |
||
675 | 2 | public function getStreamsSegment($id, $types, $resolution = 'all', $series_type = 'distance') { |
|
682 | } |
||
683 |