Conditions | 11 |
Paths | 6 |
Total Lines | 16 |
Code Lines | 13 |
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 |
||
68 | public function getGreetings() |
||
69 | { |
||
70 | $h = Carbon::now()->format('H'); |
||
71 | |||
72 | if ($h >= 0 && $h < 6) { |
||
73 | return "<i class='fa far fa-surprise fa-2x'></i> Wow, ini masih pagi loh "; |
||
74 | } elseif ($h >= 6 && $h < 11) { |
||
75 | return "<i class='fa far fa-laugh-beam fa-2x'></i> Selamat pagi "; |
||
76 | } elseif ($h >= 11 && $h <= 14) { |
||
77 | return "<i class='fa far fa-smile-wink fa-2x'></i> Selamat siang "; |
||
78 | } elseif ($h > 14 && $h <= 16) { |
||
79 | return "<i class='fa far fa-smile-beam fa-2x'></i> Selamat sore "; |
||
80 | } elseif ($h >= 17 && $h < 20) { |
||
81 | return "<i class='fa far fa-grin-stars fa-2x'></i> Senja yang indah ya "; |
||
82 | } else { |
||
83 | return "<i class='fa far fa-bed fa-2x'></i> Sudah malam, sebaiknya kamu istirahat "; |
||
84 | } |
||
87 |