Complex classes like PlayerSkills 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 PlayerSkills, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
10 | class PlayerSkills implements PlayerSkillsAverageInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var int $playerId |
||
14 | * |
||
15 | * @ORM\Id |
||
16 | * @ORM\GeneratedValue |
||
17 | * @ORM\Column(type="integer") |
||
18 | */ |
||
19 | private $id; |
||
20 | |||
21 | /** |
||
22 | * @var Player |
||
23 | * |
||
24 | * @ORM\OneToOne(targetEntity="Player", cascade={"all"}) |
||
25 | */ |
||
26 | private $player; |
||
27 | |||
28 | /** |
||
29 | * @var int |
||
30 | * |
||
31 | * @ORM\Column(type="integer") |
||
32 | */ |
||
33 | private $tackling = 1; |
||
34 | |||
35 | /** |
||
36 | * @var int |
||
37 | * |
||
38 | * @ORM\Column(type="integer") |
||
39 | */ |
||
40 | private $passing = 1; |
||
41 | |||
42 | /** |
||
43 | * @var int |
||
44 | * |
||
45 | * @ORM\Column(type="integer") |
||
46 | */ |
||
47 | private $shooting = 1; |
||
48 | |||
49 | /** |
||
50 | * @var int |
||
51 | * |
||
52 | * @ORM\Column(type="integer") |
||
53 | */ |
||
54 | private $heading = 1; |
||
55 | |||
56 | /** |
||
57 | * @var int |
||
58 | * |
||
59 | * @ORM\Column(type="integer") |
||
60 | */ |
||
61 | private $speed = 1; |
||
62 | |||
63 | /** |
||
64 | * @var int |
||
65 | * |
||
66 | * @ORM\Column(type="integer") |
||
67 | */ |
||
68 | private $crossing = 1; |
||
69 | |||
70 | /** |
||
71 | * @var int |
||
72 | * |
||
73 | * @ORM\Column(type="integer") |
||
74 | */ |
||
75 | private $technics = 1; |
||
76 | |||
77 | /** |
||
78 | * @var int |
||
79 | * |
||
80 | * @ORM\Column(type="integer") |
||
81 | */ |
||
82 | private $intelligence = 1; |
||
83 | |||
84 | /** |
||
85 | * @var int |
||
86 | * |
||
87 | * @ORM\Column(type="integer") |
||
88 | */ |
||
89 | private $safety = 1; |
||
90 | |||
91 | /** |
||
92 | * @var int |
||
93 | * |
||
94 | * @ORM\Column(type="integer") |
||
95 | */ |
||
96 | private $dribbling = 1; |
||
97 | |||
98 | /** |
||
99 | * @var int |
||
100 | * |
||
101 | * @ORM\Column(type="integer") |
||
102 | */ |
||
103 | private $changeTackling = 0; |
||
104 | |||
105 | /** |
||
106 | * @var int |
||
107 | * |
||
108 | * @ORM\Column(type="integer") |
||
109 | */ |
||
110 | private $changePassing = 0; |
||
111 | |||
112 | /** |
||
113 | * @var int |
||
114 | * |
||
115 | * @ORM\Column(type="integer") |
||
116 | */ |
||
117 | private $changeShooting = 0; |
||
118 | |||
119 | /** |
||
120 | * @var int |
||
121 | * |
||
122 | * @ORM\Column(type="integer") |
||
123 | */ |
||
124 | private $changeHeading = 0; |
||
125 | |||
126 | /** |
||
127 | * @var int |
||
128 | * |
||
129 | * @ORM\Column(type="integer") |
||
130 | */ |
||
131 | private $changeSpeed = 0; |
||
132 | |||
133 | /** |
||
134 | * @var int |
||
135 | * |
||
136 | * @ORM\Column(type="integer") |
||
137 | */ |
||
138 | private $changeCrossing = 0; |
||
139 | |||
140 | /** |
||
141 | * @var int |
||
142 | * |
||
143 | * @ORM\Column(type="integer") |
||
144 | */ |
||
145 | private $changeTechnics = 0; |
||
146 | |||
147 | /** |
||
148 | * @var int |
||
149 | * |
||
150 | * @ORM\Column(type="integer") |
||
151 | */ |
||
152 | private $changeIntelligence = 0; |
||
153 | |||
154 | /** |
||
155 | * @var int |
||
156 | * |
||
157 | * @ORM\Column(type="integer") |
||
158 | */ |
||
159 | private $changeSafety = 0; |
||
160 | |||
161 | /** |
||
162 | * @var int |
||
163 | * |
||
164 | * @ORM\Column(type="integer") |
||
165 | */ |
||
166 | private $changeDribbling = 0; |
||
167 | |||
168 | /** |
||
169 | * @var int |
||
170 | * |
||
171 | * @ORM\Column(type="integer") |
||
172 | */ |
||
173 | private $trainingValueTackling = 0; |
||
174 | |||
175 | /** |
||
176 | * @var int |
||
177 | * |
||
178 | * @ORM\Column(type="integer") |
||
179 | */ |
||
180 | private $trainingValuePassing = 0; |
||
181 | |||
182 | /** |
||
183 | * @var int |
||
184 | * |
||
185 | * @ORM\Column(type="integer") |
||
186 | */ |
||
187 | private $trainingValueShooting = 0; |
||
188 | |||
189 | /** |
||
190 | * @var int |
||
191 | * |
||
192 | * @ORM\Column(type="integer") |
||
193 | */ |
||
194 | private $trainingValueHeading = 0; |
||
195 | |||
196 | /** |
||
197 | * @var int |
||
198 | * |
||
199 | * @ORM\Column(type="integer") |
||
200 | */ |
||
201 | private $trainingValueSpeed = 0; |
||
202 | |||
203 | /** |
||
204 | * @var int |
||
205 | * |
||
206 | * @ORM\Column(type="integer") |
||
207 | */ |
||
208 | private $trainingValueCrossing = 0; |
||
209 | |||
210 | /** |
||
211 | * @var int |
||
212 | * |
||
213 | * @ORM\Column(type="integer") |
||
214 | */ |
||
215 | private $trainingValueTechnics = 0; |
||
216 | |||
217 | /** |
||
218 | * @var int |
||
219 | * |
||
220 | * @ORM\Column(type="integer") |
||
221 | */ |
||
222 | private $trainingValueIntelligence = 0; |
||
223 | |||
224 | /** |
||
225 | * @var int |
||
226 | * |
||
227 | * @ORM\Column(type="integer") |
||
228 | */ |
||
229 | private $trainingValueSafety = 0; |
||
230 | |||
231 | /** |
||
232 | * @var int |
||
233 | * |
||
234 | * @ORM\Column(type="integer") |
||
235 | */ |
||
236 | private $trainingValueDribbling = 0; |
||
237 | |||
238 | /** |
||
239 | * @return int |
||
240 | */ |
||
241 | public function getId() |
||
245 | |||
246 | /** |
||
247 | * @return Player |
||
248 | */ |
||
249 | 28 | public function getPlayer() |
|
253 | |||
254 | /** |
||
255 | * @return int |
||
256 | */ |
||
257 | 34 | public function getTackling() |
|
261 | |||
262 | /** |
||
263 | * @return int |
||
264 | */ |
||
265 | 29 | public function getPassing() |
|
269 | |||
270 | /** |
||
271 | * @return int |
||
272 | */ |
||
273 | 34 | public function getShooting() |
|
277 | |||
278 | /** |
||
279 | * @return int |
||
280 | */ |
||
281 | 29 | public function getCrossing() |
|
285 | |||
286 | /** |
||
287 | * @return int |
||
288 | */ |
||
289 | 29 | public function getDribbling() |
|
293 | |||
294 | /** |
||
295 | * @return int |
||
296 | */ |
||
297 | 29 | public function getHeading() |
|
301 | |||
302 | /** |
||
303 | * @return int |
||
304 | */ |
||
305 | 29 | public function getIntelligence() |
|
309 | |||
310 | /** |
||
311 | * @return int |
||
312 | */ |
||
313 | 29 | public function getSafety() |
|
317 | |||
318 | /** |
||
319 | * @return int |
||
320 | */ |
||
321 | 29 | public function getSpeed() |
|
325 | |||
326 | /** |
||
327 | * @return int |
||
328 | */ |
||
329 | 29 | public function getTechnics() |
|
333 | |||
334 | /** |
||
335 | * @param Player $player |
||
336 | */ |
||
337 | 28 | public function setPlayer(Player $player) |
|
344 | |||
345 | /** |
||
346 | * @param int $id |
||
347 | */ |
||
348 | public function setId($id) |
||
352 | |||
353 | /** |
||
354 | * @param int $amount |
||
355 | */ |
||
356 | 5 | public function setCrossing($amount) |
|
360 | |||
361 | /** |
||
362 | * @param int $amount |
||
363 | */ |
||
364 | 4 | public function setTechnics($amount) |
|
368 | |||
369 | /** |
||
370 | * @param int $amount |
||
371 | */ |
||
372 | 4 | public function setSpeed($amount) |
|
376 | |||
377 | /** |
||
378 | * @param int $amount |
||
379 | */ |
||
380 | 4 | public function setHeading($amount) |
|
384 | |||
385 | /** |
||
386 | * @param int $amount |
||
387 | */ |
||
388 | 4 | public function setIntelligence($amount) |
|
392 | |||
393 | /** |
||
394 | * @param int $amount |
||
395 | */ |
||
396 | 4 | public function setSafety($amount) |
|
400 | |||
401 | /** |
||
402 | * @param int $amount |
||
403 | */ |
||
404 | 6 | public function setDribbling($amount) |
|
408 | |||
409 | /** |
||
410 | * @param int $amount |
||
411 | */ |
||
412 | 6 | public function setTackling($amount) |
|
416 | |||
417 | /** |
||
418 | * @param int $amount |
||
419 | */ |
||
420 | 4 | public function setPassing($amount) |
|
424 | |||
425 | /** |
||
426 | * @param int $amount |
||
427 | */ |
||
428 | 4 | public function setShooting($amount) |
|
432 | |||
433 | /** |
||
434 | * @param int $amount |
||
435 | */ |
||
436 | 3 | public function increaseTackling($amount) |
|
440 | |||
441 | /** |
||
442 | * @param int $amount |
||
443 | */ |
||
444 | 3 | public function decreaseTackling($amount) |
|
448 | |||
449 | /** |
||
450 | * @param int $amount |
||
451 | */ |
||
452 | 3 | public function increasePassing($amount) |
|
456 | |||
457 | /** |
||
458 | * @param int $amount |
||
459 | */ |
||
460 | 3 | public function decreasePassing($amount) |
|
464 | |||
465 | /** |
||
466 | * @param int $amount |
||
467 | */ |
||
468 | 3 | public function increaseShooting($amount) |
|
472 | |||
473 | /** |
||
474 | * @param int $amount |
||
475 | */ |
||
476 | 3 | public function decreaseShooting($amount) |
|
480 | |||
481 | /** |
||
482 | * @param int $amount |
||
483 | */ |
||
484 | 3 | public function increaseHeading($amount) |
|
488 | |||
489 | /** |
||
490 | * @param int $amount |
||
491 | */ |
||
492 | 3 | public function decreaseHeading($amount) |
|
496 | |||
497 | /** |
||
498 | * @param int $amount |
||
499 | */ |
||
500 | 3 | public function increaseSpeed($amount) |
|
504 | |||
505 | /** |
||
506 | * @param int $amount |
||
507 | */ |
||
508 | 3 | public function decreaseSpeed($amount) |
|
512 | |||
513 | /** |
||
514 | * @param int $amount |
||
515 | */ |
||
516 | 3 | public function increaseCrossing($amount) |
|
520 | |||
521 | /** |
||
522 | * @param int $amount |
||
523 | */ |
||
524 | 3 | public function decreaseCrossing($amount) |
|
528 | |||
529 | /** |
||
530 | * @param int $amount |
||
531 | */ |
||
532 | 3 | public function increaseTechnics($amount) |
|
536 | |||
537 | /** |
||
538 | * @param int $amount |
||
539 | */ |
||
540 | 3 | public function decreaseTechnics($amount) |
|
544 | |||
545 | /** |
||
546 | * @param int $amount |
||
547 | */ |
||
548 | 3 | public function increaseIntelligence($amount) |
|
552 | |||
553 | /** |
||
554 | * @param int $amount |
||
555 | */ |
||
556 | 3 | public function decreaseIntelligence($amount) |
|
560 | |||
561 | /** |
||
562 | * @param int $amount |
||
563 | */ |
||
564 | 3 | public function increaseSafety($amount) |
|
568 | |||
569 | /** |
||
570 | * @param int $amount |
||
571 | */ |
||
572 | 3 | public function decreaseSafety($amount) |
|
576 | |||
577 | /** |
||
578 | * @param int $amount |
||
579 | */ |
||
580 | 3 | public function increaseDribbling($amount) |
|
584 | |||
585 | /** |
||
586 | * @param int $amount |
||
587 | */ |
||
588 | 3 | public function decreaseDribbling($amount) |
|
592 | |||
593 | /** |
||
594 | * @return float |
||
595 | */ |
||
596 | 20 | public function getAverage() |
|
600 | |||
601 | 1 | public function initWithRandomValues() |
|
614 | |||
615 | /** |
||
616 | * @param int $value |
||
617 | */ |
||
618 | 24 | public function setAll($value) |
|
631 | |||
632 | /** |
||
633 | * @param int $value |
||
634 | */ |
||
635 | 7 | public function setAllTrainingValues($value) |
|
648 | |||
649 | /** |
||
650 | * @return int |
||
651 | */ |
||
652 | 17 | public function getMarketValue() |
|
656 | |||
657 | /** |
||
658 | * @return int |
||
659 | */ |
||
660 | 12 | public function getTrainingValueTackling() |
|
664 | |||
665 | /** |
||
666 | * @param int $amount |
||
667 | */ |
||
668 | 1 | public function setTrainingValueTackling($amount) |
|
672 | |||
673 | /** |
||
674 | * @return int |
||
675 | */ |
||
676 | 10 | public function getTrainingValuePassing() |
|
680 | |||
681 | /** |
||
682 | * @param int $amount |
||
683 | */ |
||
684 | 1 | public function setTrainingValuePassing($amount) |
|
688 | |||
689 | /** |
||
690 | * @return int |
||
691 | */ |
||
692 | 10 | public function getTrainingValueShooting() |
|
696 | |||
697 | /** |
||
698 | * @param int $amount |
||
699 | */ |
||
700 | 1 | public function setTrainingValueShooting($amount) |
|
704 | |||
705 | /** |
||
706 | * @return int |
||
707 | */ |
||
708 | 10 | public function getTrainingValueHeading() |
|
712 | |||
713 | /** |
||
714 | * @param int $amount |
||
715 | */ |
||
716 | 1 | public function setTrainingValueHeading($amount) |
|
720 | |||
721 | /** |
||
722 | * @return int |
||
723 | */ |
||
724 | 10 | public function getTrainingValueSpeed() |
|
728 | |||
729 | /** |
||
730 | * @param int $amount |
||
731 | */ |
||
732 | 1 | public function setTrainingValueSpeed($amount) |
|
736 | |||
737 | /** |
||
738 | * @return int |
||
739 | */ |
||
740 | 10 | public function getTrainingValueCrossing() |
|
744 | |||
745 | /** |
||
746 | * @param int $amount |
||
747 | */ |
||
748 | 1 | public function setTrainingValueCrossing($amount) |
|
752 | |||
753 | /** |
||
754 | * @return int |
||
755 | */ |
||
756 | 10 | public function getTrainingValueTechnics() |
|
760 | |||
761 | /** |
||
762 | * @param int $amount |
||
763 | */ |
||
764 | 1 | public function setTrainingValueTechnics($amount) |
|
768 | |||
769 | /** |
||
770 | * @return int |
||
771 | */ |
||
772 | 10 | public function getTrainingValueIntelligence() |
|
776 | |||
777 | /** |
||
778 | * @param int $amount |
||
779 | */ |
||
780 | 1 | public function setTrainingValueIntelligence($amount) |
|
784 | |||
785 | /** |
||
786 | * @return int |
||
787 | */ |
||
788 | 10 | public function getTrainingValueSafety() |
|
792 | |||
793 | /** |
||
794 | * @param int $amount |
||
795 | */ |
||
796 | 1 | public function setTrainingValueSafety($amount) |
|
800 | |||
801 | /** |
||
802 | * @return int |
||
803 | */ |
||
804 | 10 | public function getTrainingValueDribbling() |
|
808 | |||
809 | /** |
||
810 | * @param int $amount |
||
811 | */ |
||
812 | 1 | public function setTrainingValueDribbling($amount) |
|
816 | |||
817 | /** |
||
818 | * @param int $amount |
||
819 | */ |
||
820 | 6 | public function addTrainingValueTackling($amount) |
|
824 | |||
825 | /** |
||
826 | * @param int $amount |
||
827 | */ |
||
828 | 6 | public function addTrainingValuePassing($amount) |
|
832 | |||
833 | /** |
||
834 | * @param int $amount |
||
835 | */ |
||
836 | 6 | public function addTrainingValueShooting($amount) |
|
840 | |||
841 | /** |
||
842 | * @param int $amount |
||
843 | */ |
||
844 | 6 | public function addTrainingValueHeading($amount) |
|
848 | |||
849 | /** |
||
850 | * @param int $amount |
||
851 | */ |
||
852 | 6 | public function addTrainingValueSpeed($amount) |
|
856 | |||
857 | /** |
||
858 | * @param int $amount |
||
859 | */ |
||
860 | 6 | public function addTrainingValueCrossing($amount) |
|
864 | |||
865 | /** |
||
866 | * @param int $amount |
||
867 | */ |
||
868 | 6 | public function addTrainingValueTechnics($amount) |
|
872 | |||
873 | /** |
||
874 | * @param int $amount |
||
875 | */ |
||
876 | 6 | public function addTrainingValueIntelligence($amount) |
|
880 | |||
881 | /** |
||
882 | * @param int $amount |
||
883 | */ |
||
884 | 6 | public function addTrainingValueSafety($amount) |
|
888 | |||
889 | /** |
||
890 | * @param int $amount |
||
891 | */ |
||
892 | 6 | public function addTrainingValueDribbling($amount) |
|
896 | |||
897 | /** |
||
898 | * @return int |
||
899 | */ |
||
900 | 2 | public function getChangeTackling() |
|
904 | |||
905 | /** |
||
906 | * @return int |
||
907 | */ |
||
908 | 2 | public function getChangePassing() |
|
912 | |||
913 | /** |
||
914 | * @return int |
||
915 | */ |
||
916 | 2 | public function getChangeShooting() |
|
920 | |||
921 | /** |
||
922 | * @return int |
||
923 | */ |
||
924 | 2 | public function getChangeHeading() |
|
928 | |||
929 | /** |
||
930 | * @return int |
||
931 | */ |
||
932 | 2 | public function getChangeSpeed() |
|
936 | |||
937 | /** |
||
938 | * @return int |
||
939 | */ |
||
940 | 2 | public function getChangeCrossing() |
|
944 | |||
945 | /** |
||
946 | * @return int |
||
947 | */ |
||
948 | 2 | public function getChangeTechnics() |
|
952 | |||
953 | /** |
||
954 | * @return int |
||
955 | */ |
||
956 | 2 | public function getChangeIntelligence() |
|
960 | |||
961 | /** |
||
962 | * @return int |
||
963 | */ |
||
964 | 2 | public function getChangeSafety() |
|
968 | |||
969 | /** |
||
970 | * @return int |
||
971 | */ |
||
972 | 2 | public function getChangeDribbling() |
|
976 | |||
977 | 1 | public function decreaseTrainingValues() |
|
990 | |||
991 | 3 | public function updateSkills() |
|
1004 | |||
1005 | /** |
||
1006 | * @param string $skill |
||
1007 | */ |
||
1008 | 3 | private function updateSkill($skill) |
|
1016 | |||
1017 | /** |
||
1018 | * @param int $trainingValue |
||
1019 | * |
||
1020 | * @return int |
||
1021 | */ |
||
1022 | 3 | private function calculateSkillChange($trainingValue) |
|
1037 | |||
1038 | /** |
||
1039 | * @param string $skill |
||
1040 | * @param int $amount |
||
1041 | */ |
||
1042 | 3 | private function increaseSkill($skill, $amount) |
|
1046 | |||
1047 | /** |
||
1048 | * @param string $skill |
||
1049 | * @param int $amount |
||
1050 | */ |
||
1051 | 3 | private function decreaseSkill($skill, $amount) |
|
1055 | |||
1056 | /** |
||
1057 | * @param string $skill |
||
1058 | * @param int $amount |
||
1059 | */ |
||
1060 | 7 | private function setSkill($skill, $amount) |
|
1064 | |||
1065 | /** |
||
1066 | * @param PlayerSkillsAverageInterface $a |
||
1067 | * @param PlayerSkillsAverageInterface $b |
||
1068 | * |
||
1069 | * @return bool |
||
1070 | */ |
||
1071 | 2 | static public function compareAverage(PlayerSkillsAverageInterface $a, PlayerSkillsAverageInterface $b) |
|
1075 | } |
||
1076 |