Conditions | 2 |
Paths | 2 |
Total Lines | 71 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
9 | public function run() |
||
10 | { |
||
11 | $createdAt = Carbon::now()->format('Y-m-d H:i:s'); |
||
12 | |||
13 | $achievements = [ |
||
14 | [ |
||
15 | 'id' => 1, |
||
16 | 'name' => 'Level 10', |
||
17 | 'description' => 'Reach Level 10.', |
||
18 | 'points' => 10, |
||
19 | 'created_at' => $createdAt, |
||
20 | 'updated_at' => $createdAt, |
||
21 | 'criterias' => [ |
||
22 | [ |
||
23 | 'type' => 'reach_level', |
||
24 | 'name' => 'Reach level 10', |
||
25 | 'max_value' => 10, |
||
26 | ] |
||
27 | ], |
||
28 | ], |
||
29 | [ |
||
30 | 'id' => 2, |
||
31 | 'name' => 'Level 20', |
||
32 | 'description' => 'Reach Level 20.', |
||
33 | 'points' => 10, |
||
34 | 'created_at' => $createdAt, |
||
35 | 'updated_at' => $createdAt, |
||
36 | 'criterias' => [ |
||
37 | [ |
||
38 | 'type' => 'reach_level', |
||
39 | 'name' => 'Reach level 20', |
||
40 | 'max_value' => 20, |
||
41 | ] |
||
42 | ], |
||
43 | ], |
||
44 | [ |
||
45 | 'id' => 3, |
||
46 | 'name' => 'Level 30', |
||
47 | 'description' => 'Reach Level 30.', |
||
48 | 'points' => 10, |
||
49 | 'created_at' => $createdAt, |
||
50 | 'updated_at' => $createdAt, |
||
51 | 'criterias' => [ |
||
52 | [ |
||
53 | 'type' => 'reach_level', |
||
54 | 'name' => 'Reach level 30', |
||
55 | 'max_value' => 30, |
||
56 | ] |
||
57 | ], |
||
58 | ], |
||
59 | [ |
||
60 | 'id' => 4, |
||
61 | 'name' => '50 Quests Completed', |
||
62 | 'description' => 'Complete 50 quests.', |
||
63 | 'points' => 10, |
||
64 | 'created_at' => $createdAt, |
||
65 | 'updated_at' => $createdAt, |
||
66 | 'criterias' => [ |
||
67 | [ |
||
68 | 'type' => 'complete_quests', |
||
69 | 'name' => 'Complete 50 quests', |
||
70 | 'max_value' => 50, |
||
71 | ] |
||
72 | ], |
||
73 | ], |
||
74 | ]; |
||
75 | |||
76 | foreach ($achievements as $achievement) { |
||
77 | $this->createAchievement($achievement); |
||
78 | } |
||
79 | } |
||
80 | |||
94 |