Conditions | 15 |
Paths | 19 |
Total Lines | 52 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
16 | public function toArray($request) |
||
17 | { |
||
18 | $type = $this->experienceTypeName(); |
||
19 | $translations = []; |
||
20 | $dates = []; |
||
21 | switch ($type) { |
||
22 | case 'experience_work': |
||
23 | $dates = [ |
||
24 | 'start_date' => $this->start_date ? $this->start_date->format('Y-m-d') : null, |
||
25 | 'end_date' => $this->end_date ? $this->end_date->format('Y-m-d') : null, |
||
26 | ]; |
||
27 | break; |
||
28 | case 'experience_award': |
||
29 | $dates = [ |
||
30 | 'awarded_date' => $this->awarded_date ? $this->awarded_date->format('Y-m-d') : null, |
||
31 | ]; |
||
32 | $translations = [ |
||
33 | 'award_recipient_type' => $this->award_recipient_type->getTranslations('name'), |
||
34 | 'award_recognition_type' => $this->award_recognition_type->getTranslations('name'), |
||
35 | ]; |
||
36 | break; |
||
37 | case 'experience_community': |
||
38 | $dates = [ |
||
39 | 'start_date' => $this->start_date ? $this->start_date->format('Y-m-d') : null, |
||
40 | 'end_date' => $this->end_date ? $this->end_date->format('Y-m-d') : null, |
||
41 | ]; |
||
42 | break; |
||
43 | case 'experience_education': |
||
44 | $dates = [ |
||
45 | 'start_date' => $this->start_date ? $this->start_date->format('Y-m-d') : null, |
||
46 | 'end_date' => $this->end_date ? $this->end_date->format('Y-m-d') : null, |
||
47 | ]; |
||
48 | $translations = [ |
||
49 | 'education_status' => $this->education_status->getTranslations('name'), |
||
50 | 'education_type' => $this->education_type->getTranslations('name'), |
||
51 | ]; |
||
52 | break; |
||
53 | case 'experience_personal': |
||
54 | $dates = [ |
||
55 | 'start_date' => $this->start_date ? $this->start_date->format('Y-m-d') : null, |
||
56 | 'end_date' => $this->end_date ? $this->end_date->format('Y-m-d') : null, |
||
57 | ]; |
||
58 | break; |
||
59 | } |
||
60 | return array_merge( |
||
61 | parent::toArray($request), |
||
62 | $translations, |
||
63 | [ |
||
64 | 'type' => $type, |
||
65 | 'experience_skills' => JsonResource::collection($this->whenLoaded('experience_skills')), |
||
66 | ], |
||
67 | $dates |
||
68 | ); |
||
71 |