Complex classes like Event 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 Event, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | class Event extends Entity implements EventInterface { |
||
18 | |||
19 | /** |
||
20 | * {@inheritdoc} |
||
21 | */ |
||
22 | protected static $propertyMapDefinition; |
||
23 | |||
24 | /** |
||
25 | * The primary identifier. |
||
26 | * |
||
27 | * @var mixed |
||
28 | */ |
||
29 | protected $id; |
||
30 | |||
31 | /** |
||
32 | * The name. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $name; |
||
37 | |||
38 | /** |
||
39 | * The league of this event. |
||
40 | * |
||
41 | * @var \TheSportsDb\Entity\LeagueInterface |
||
42 | */ |
||
43 | protected $league; |
||
44 | |||
45 | /** |
||
46 | * The filename. |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | protected $filename; |
||
51 | |||
52 | /** |
||
53 | * The season. |
||
54 | * |
||
55 | * @var \TheSportsDb\Entity\SeasonInterface |
||
56 | */ |
||
57 | protected $season; |
||
58 | |||
59 | /** |
||
60 | * The description. |
||
61 | * |
||
62 | * @var string |
||
63 | */ |
||
64 | protected $description; |
||
65 | |||
66 | /** |
||
67 | * The home score. |
||
68 | * |
||
69 | * @var int |
||
70 | */ |
||
71 | protected $homeScore; |
||
72 | |||
73 | /** |
||
74 | * The round. |
||
75 | * |
||
76 | * @var int |
||
77 | */ |
||
78 | protected $round; |
||
79 | |||
80 | /** |
||
81 | * The away score. |
||
82 | * |
||
83 | * @var int |
||
84 | */ |
||
85 | protected $awayScore; |
||
86 | |||
87 | /** |
||
88 | * The number of specators. |
||
89 | * |
||
90 | * @var int |
||
91 | */ |
||
92 | protected $specators; |
||
93 | |||
94 | /** |
||
95 | * The home goal details. |
||
96 | * |
||
97 | * @var string |
||
98 | */ |
||
99 | protected $homeGoalDetails; |
||
100 | |||
101 | /** |
||
102 | * The home red cards. |
||
103 | * |
||
104 | * @var string |
||
105 | */ |
||
106 | protected $homeRedCards; |
||
107 | |||
108 | /** |
||
109 | * The home yellow cards. |
||
110 | * |
||
111 | * @var string |
||
112 | */ |
||
113 | protected $homeYellowCards; |
||
114 | |||
115 | /** |
||
116 | * The home lineup - goalkeeper. |
||
117 | * |
||
118 | * @var string |
||
119 | */ |
||
120 | protected $homeLineupGoalkeeper; |
||
121 | |||
122 | /** |
||
123 | * The home lineup - defense. |
||
124 | * |
||
125 | * @var string |
||
126 | */ |
||
127 | protected $homeLineupDefense; |
||
128 | |||
129 | /** |
||
130 | * The home lineup - midfield. |
||
131 | * |
||
132 | * @var string |
||
133 | */ |
||
134 | protected $homeLineupMidfield; |
||
135 | |||
136 | /** |
||
137 | * The home lineup - forward. |
||
138 | * |
||
139 | * @var string |
||
140 | */ |
||
141 | protected $homeLineupForward; |
||
142 | |||
143 | /** |
||
144 | * The home lineup - substitutes. |
||
145 | * |
||
146 | * @var string |
||
147 | */ |
||
148 | protected $homeLineupSubstitutes; |
||
149 | |||
150 | /** |
||
151 | * The home formation. |
||
152 | * |
||
153 | * @var string |
||
154 | */ |
||
155 | protected $homeFormation; |
||
156 | |||
157 | /** |
||
158 | * The away red cards. |
||
159 | * |
||
160 | * @var string |
||
161 | */ |
||
162 | protected $awayRedCards; |
||
163 | |||
164 | /** |
||
165 | * The away yellow cards. |
||
166 | * |
||
167 | * @var string |
||
168 | */ |
||
169 | protected $awayYellowCards; |
||
170 | |||
171 | /** |
||
172 | * The away goal details. |
||
173 | * |
||
174 | * @var string |
||
175 | */ |
||
176 | protected $awayGoalDetails; |
||
177 | |||
178 | /** |
||
179 | * The away lineup - goalkeeper. |
||
180 | * |
||
181 | * @var string |
||
182 | */ |
||
183 | protected $awayLineupGoalkeeper; |
||
184 | |||
185 | /** |
||
186 | * The away lineup - defense. |
||
187 | * |
||
188 | * @var string |
||
189 | */ |
||
190 | protected $awayLineupDefense; |
||
191 | |||
192 | /** |
||
193 | * The away lineup - midfield. |
||
194 | * |
||
195 | * @var string |
||
196 | */ |
||
197 | protected $awayLineupMidfield; |
||
198 | |||
199 | /** |
||
200 | * The away lineup - forward. |
||
201 | * |
||
202 | * @var string |
||
203 | */ |
||
204 | protected $awayLineupForward; |
||
205 | |||
206 | /** |
||
207 | * The away lineup - substitutes. |
||
208 | * |
||
209 | * @var string |
||
210 | */ |
||
211 | protected $awayLineupSubstitutes; |
||
212 | |||
213 | /** |
||
214 | * The away formation. |
||
215 | * |
||
216 | * @var string |
||
217 | */ |
||
218 | protected $awayFormation; |
||
219 | |||
220 | /** |
||
221 | * The home shots. |
||
222 | * |
||
223 | * @var int |
||
224 | */ |
||
225 | protected $homeShots; |
||
226 | |||
227 | /** |
||
228 | * The away shots. |
||
229 | * |
||
230 | * @var int |
||
231 | */ |
||
232 | protected $awayShots; |
||
233 | |||
234 | /** |
||
235 | * The date. |
||
236 | * |
||
237 | * @var string |
||
238 | */ |
||
239 | protected $date; |
||
240 | |||
241 | /** |
||
242 | * The TV station. |
||
243 | * |
||
244 | * @var string |
||
245 | */ |
||
246 | protected $tvStation; |
||
247 | |||
248 | /** |
||
249 | * The home team. |
||
250 | * |
||
251 | * @var \TheSportsDb\Entity\TeamInterface |
||
252 | */ |
||
253 | protected $homeTeam; |
||
254 | |||
255 | /** |
||
256 | * The away team. |
||
257 | * |
||
258 | * @var \TheSportsDb\Entity\TeamInterface |
||
259 | */ |
||
260 | protected $awayTeam; |
||
261 | |||
262 | /** |
||
263 | * The result. |
||
264 | * |
||
265 | * @var string |
||
266 | */ |
||
267 | protected $result; |
||
268 | |||
269 | /** |
||
270 | * The circuit. |
||
271 | * |
||
272 | * @var string |
||
273 | */ |
||
274 | protected $circuit; |
||
275 | |||
276 | /** |
||
277 | * The country. |
||
278 | * |
||
279 | * @var string |
||
280 | */ |
||
281 | protected $country; |
||
282 | |||
283 | /** |
||
284 | * The city. |
||
285 | * |
||
286 | * @var string |
||
287 | */ |
||
288 | protected $city; |
||
289 | |||
290 | /** |
||
291 | * The poster URL. |
||
292 | * |
||
293 | * @var string |
||
294 | */ |
||
295 | protected $poster; |
||
296 | |||
297 | /** |
||
298 | * The thumbnail URL. |
||
299 | * |
||
300 | * @var string |
||
301 | */ |
||
302 | protected $thumb; |
||
303 | |||
304 | /** |
||
305 | * The banner URL. |
||
306 | * |
||
307 | * @var string |
||
308 | */ |
||
309 | protected $banner; |
||
310 | |||
311 | /** |
||
312 | * The map URL. |
||
313 | * |
||
314 | * @var string |
||
315 | */ |
||
316 | protected $map; |
||
317 | |||
318 | /** |
||
319 | * Whether this player is locked or not. |
||
320 | * |
||
321 | * @var string |
||
322 | */ |
||
323 | protected $locked; |
||
324 | |||
325 | /** |
||
326 | * {@inheritdoc} |
||
327 | */ |
||
328 | 1 | public function getId() { |
|
331 | |||
332 | /** |
||
333 | * {@inheritdoc} |
||
334 | */ |
||
335 | 1 | public function getName() { |
|
338 | |||
339 | /** |
||
340 | * {@inheritdoc} |
||
341 | */ |
||
342 | 1 | public function getLeague() { |
|
345 | |||
346 | /** |
||
347 | * {@inheritdoc} |
||
348 | */ |
||
349 | 1 | public function getFilename() { |
|
352 | |||
353 | /** |
||
354 | * {@inheritdoc} |
||
355 | */ |
||
356 | 1 | public function getSeason() { |
|
359 | |||
360 | /** |
||
361 | * {@inheritdoc} |
||
362 | */ |
||
363 | 1 | public function getDescription() { |
|
366 | |||
367 | /** |
||
368 | * {@inheritdoc} |
||
369 | */ |
||
370 | 1 | public function getHomeScore() { |
|
373 | |||
374 | /** |
||
375 | * {@inheritdoc} |
||
376 | */ |
||
377 | 1 | public function getRound() { |
|
380 | |||
381 | /** |
||
382 | * {@inheritdoc} |
||
383 | */ |
||
384 | 1 | public function getAwayScore() { |
|
387 | |||
388 | /** |
||
389 | * {@inheritdoc} |
||
390 | */ |
||
391 | 1 | public function getSpecators() { |
|
394 | |||
395 | /** |
||
396 | * {@inheritdoc} |
||
397 | */ |
||
398 | 1 | public function getHomeGoalDetails() { |
|
401 | |||
402 | /** |
||
403 | * {@inheritdoc} |
||
404 | */ |
||
405 | 1 | public function getHomeRedCards() { |
|
408 | |||
409 | /** |
||
410 | * {@inheritdoc} |
||
411 | */ |
||
412 | 1 | public function getHomeYellowCards() { |
|
415 | |||
416 | /** |
||
417 | * {@inheritdoc} |
||
418 | */ |
||
419 | 1 | public function getHomeLineupGoalkeeper() { |
|
422 | |||
423 | /** |
||
424 | * {@inheritdoc} |
||
425 | */ |
||
426 | 1 | public function getHomeLineupDefense() { |
|
429 | |||
430 | /** |
||
431 | * {@inheritdoc} |
||
432 | */ |
||
433 | 1 | public function getHomeLineupMidfield() { |
|
436 | |||
437 | /** |
||
438 | * {@inheritdoc} |
||
439 | */ |
||
440 | 1 | public function getHomeLineupForward() { |
|
443 | |||
444 | /** |
||
445 | * {@inheritdoc} |
||
446 | */ |
||
447 | 1 | public function getHomeLineupSubstitutes() { |
|
448 | 1 | return $this->homeLineupSubstitutes; |
|
449 | } |
||
450 | |||
451 | /** |
||
452 | * {@inheritdoc} |
||
453 | */ |
||
454 | 1 | public function getHomeFormation() { |
|
457 | |||
458 | /** |
||
459 | * {@inheritdoc} |
||
460 | */ |
||
461 | 1 | public function getAwayRedCards() { |
|
464 | |||
465 | /** |
||
466 | * {@inheritdoc} |
||
467 | */ |
||
468 | 1 | public function getAwayYellowCards() { |
|
471 | |||
472 | /** |
||
473 | * {@inheritdoc} |
||
474 | */ |
||
475 | 1 | public function getAwayGoalDetails() { |
|
478 | |||
479 | /** |
||
480 | * {@inheritdoc} |
||
481 | */ |
||
482 | 1 | public function getAwayLineupGoalkeeper() { |
|
485 | |||
486 | /** |
||
487 | * {@inheritdoc} |
||
488 | */ |
||
489 | 1 | public function getAwayLineupDefense() { |
|
492 | |||
493 | /** |
||
494 | * {@inheritdoc} |
||
495 | */ |
||
496 | 1 | public function getAwayLineupMidfield() { |
|
499 | |||
500 | /** |
||
501 | * {@inheritdoc} |
||
502 | */ |
||
503 | 1 | public function getAwayLineupForward() { |
|
506 | |||
507 | /** |
||
508 | * {@inheritdoc} |
||
509 | */ |
||
510 | 1 | public function getAwayLineupSubstitutes() { |
|
513 | |||
514 | /** |
||
515 | * {@inheritdoc} |
||
516 | */ |
||
517 | 1 | public function getAwayFormation() { |
|
520 | |||
521 | /** |
||
522 | * {@inheritdoc} |
||
523 | */ |
||
524 | 1 | public function getHomeShots() { |
|
527 | |||
528 | /** |
||
529 | * {@inheritdoc} |
||
530 | */ |
||
531 | 1 | public function getAwayShots() { |
|
534 | |||
535 | /** |
||
536 | * {@inheritdoc} |
||
537 | */ |
||
538 | 1 | public function getDate() { |
|
541 | |||
542 | /** |
||
543 | * {@inheritdoc} |
||
544 | */ |
||
545 | 1 | public function getTvStation() { |
|
548 | |||
549 | /** |
||
550 | * {@inheritdoc} |
||
551 | */ |
||
552 | 1 | public function getHomeTeam() { |
|
555 | |||
556 | /** |
||
557 | * {@inheritdoc} |
||
558 | */ |
||
559 | 1 | public function getAwayTeam() { |
|
562 | |||
563 | /** |
||
564 | * {@inheritdoc} |
||
565 | */ |
||
566 | 1 | public function getResult() { |
|
569 | |||
570 | /** |
||
571 | * {@inheritdoc} |
||
572 | */ |
||
573 | 1 | public function getCircuit() { |
|
576 | |||
577 | /** |
||
578 | * {@inheritdoc} |
||
579 | */ |
||
580 | 1 | public function getCountry() { |
|
583 | |||
584 | /** |
||
585 | * {@inheritdoc} |
||
586 | */ |
||
587 | 1 | public function getCity() { |
|
590 | |||
591 | /** |
||
592 | * {@inheritdoc} |
||
593 | */ |
||
594 | 1 | public function getPoster() { |
|
597 | |||
598 | /** |
||
599 | * {@inheritdoc} |
||
600 | */ |
||
601 | 1 | public function getThumb() { |
|
604 | |||
605 | /** |
||
606 | * {@inheritdoc} |
||
607 | */ |
||
608 | 1 | public function getBanner() { |
|
611 | |||
612 | /** |
||
613 | * {@inheritdoc} |
||
614 | */ |
||
615 | 1 | public function getMap() { |
|
618 | |||
619 | /** |
||
620 | * {@inheritdoc} |
||
621 | */ |
||
622 | 1 | public function getLocked() { |
|
625 | |||
626 | /** |
||
627 | * Transforms the league property to a league entity. |
||
628 | * |
||
629 | * @param mixed $value |
||
630 | * The source value of the league property. |
||
631 | * @param \stdClass $context |
||
632 | * The source object representing this event. |
||
633 | * @param EntityManagerInterface $entityManager |
||
634 | * The entity manager. |
||
635 | * |
||
636 | * @return \TheSportsDb\Entity\LeagueInterface |
||
637 | * The league entity. |
||
638 | */ |
||
639 | 1 | public static function transformLeague($value, $context, EntityManagerInterface $entityManager) { |
|
642 | |||
643 | /** |
||
644 | * Transforms the season property to a season entity. |
||
645 | * |
||
646 | * @param mixed $value |
||
647 | * The source value of the season property. |
||
648 | * @param \stdClass $context |
||
649 | * The source object representing this event. |
||
650 | * @param EntityManagerInterface $entityManager |
||
651 | * The entity manager. |
||
652 | * |
||
653 | * @return \TheSportsDb\Entity\SeasonInterface |
||
654 | * The season entity. |
||
655 | */ |
||
656 | 1 | public static function transformSeason($value, $context, EntityManagerInterface $entityManager) { |
|
663 | |||
664 | /** |
||
665 | * Transforms the home team property to a team entity. |
||
666 | * |
||
667 | * @param mixed $value |
||
668 | * The source value of the home team property. |
||
669 | * @param \stdClass $context |
||
670 | * The source object representing this event. |
||
671 | * @param EntityManagerInterface $entityManager |
||
672 | * The entity manager. |
||
673 | * |
||
674 | * @return \TheSportsDb\Entity\TeamInterface |
||
675 | * The team entity. |
||
676 | */ |
||
677 | 1 | public static function transformHomeTeam($value, $context, EntityManagerInterface $entityManager) { |
|
680 | |||
681 | /** |
||
682 | * Transforms the away team property to a team entity. |
||
683 | * |
||
684 | * @param mixed $value |
||
685 | * The source value of the away team property. |
||
686 | * @param \stdClass $context |
||
687 | * The source object representing this event. |
||
688 | * @param EntityManagerInterface $entityManager |
||
689 | * The entity manager. |
||
690 | * |
||
691 | * @return \TheSportsDb\Entity\TeamInterface |
||
692 | * The team entity. |
||
693 | */ |
||
694 | 1 | public static function transformAwayTeam($value, $context, EntityManagerInterface $entityManager) { |
|
697 | |||
698 | /** |
||
699 | * {@inhertidoc} |
||
700 | */ |
||
701 | 1 | protected static function initPropertyMapDefinition() { |
|
898 | |||
899 | public static function transformDateEvent($value, $context) { |
||
903 | |||
904 | public static function transformEventTime($value) { |
||
906 | |||
907 | public static function reverseEventTime($value, Event $context) { |
||
910 | |||
911 | } |
||
912 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.