Conditions | 11 |
Paths | 14 |
Total Lines | 39 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
21 | public function authorize() |
||
22 | { |
||
23 | $user = $this->user(); |
||
24 | if (!$user->can('create', ExperienceSkill::class)) { |
||
25 | return false; |
||
26 | } |
||
27 | |||
28 | $experienceSkills = $this->all(); |
||
29 | foreach ($experienceSkills as $experienceSkill) { |
||
30 | $experience_type = $experienceSkill['experience_type']; |
||
31 | $experience_id = (int)$experienceSkill['experience_id']; |
||
32 | $experience = null; |
||
33 | switch ($experience_type) { |
||
34 | case 'experience_work': |
||
35 | $experience = ExperienceWork::find($experience_id); |
||
36 | break; |
||
37 | case 'experience_award': |
||
38 | $experience = ExperienceAward::find($experience_id); |
||
39 | break; |
||
40 | case 'experience_community': |
||
41 | $experience = ExperienceCommunity::find($experience_id); |
||
42 | break; |
||
43 | case 'experience_education': |
||
44 | $experience = ExperienceEducation::find($experience_id); |
||
45 | break; |
||
46 | case 'experience_personal': |
||
47 | $experience = ExperiencePersonal::find($experience_id); |
||
48 | break; |
||
49 | } |
||
50 | |||
51 | if ($experience === null || |
||
52 | $user === null || |
||
53 | !$user->can('update', $experience) |
||
54 | ) { |
||
55 | return false; |
||
56 | } |
||
57 | } |
||
58 | |||
59 | return true; |
||
60 | } |
||
86 |