Conditions | 14 |
Paths | 322 |
Total Lines | 76 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
17 | function smarty_modifier_timespan($input) |
||
18 | { |
||
19 | $remaining = abs(floor($input)); |
||
20 | |||
21 | $seconds = $remaining % 60; |
||
22 | $remaining = $remaining - $seconds; |
||
23 | |||
24 | $minutes = $remaining % (60 * 60); |
||
25 | $remaining = $remaining - $minutes; |
||
26 | $minutes /= 60; |
||
27 | |||
28 | $hours = $remaining % (60 * 60 * 24); |
||
29 | $remaining = $remaining - $hours; |
||
30 | $hours /= (60 * 60); |
||
31 | |||
32 | $days = $remaining % (60 * 60 * 24 * 7); |
||
33 | $weeks = $remaining - $days; |
||
34 | $days /= (60 * 60 * 24); |
||
35 | $weeks /= (60 * 60 * 24 * 7); |
||
36 | |||
37 | $stringval = ''; |
||
38 | $trip = false; |
||
39 | |||
40 | if ($weeks > 0) { |
||
41 | $stringval .= "${weeks}w "; |
||
42 | } |
||
43 | |||
44 | if ($days > 0) { |
||
45 | if ($stringval !== '') { |
||
46 | $trip = true; |
||
47 | } |
||
48 | |||
49 | $stringval .= "${days}d "; |
||
50 | |||
51 | if ($trip) { |
||
52 | return trim($stringval); |
||
53 | } |
||
54 | } |
||
55 | |||
56 | if ($hours > 0) { |
||
57 | if ($stringval !== '') { |
||
58 | $trip = true; |
||
59 | } |
||
60 | |||
61 | $stringval .= "${hours}h "; |
||
62 | |||
63 | if ($trip) { |
||
64 | return trim($stringval); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | if ($minutes > 0) { |
||
69 | if ($stringval !== '') { |
||
70 | $trip = true; |
||
71 | } |
||
72 | |||
73 | $stringval .= "${minutes}m "; |
||
74 | |||
75 | if ($trip) { |
||
76 | return trim($stringval); |
||
77 | } |
||
78 | } |
||
79 | |||
80 | if ($seconds > 0) { |
||
81 | if ($stringval !== '') { |
||
82 | $trip = true; |
||
83 | } |
||
84 | |||
85 | $stringval .= "${seconds}s "; |
||
86 | |||
87 | if ($trip) { |
||
88 | return trim($stringval); |
||
89 | } |
||
90 | } |
||
91 | |||
92 | return trim($stringval); |
||
93 | } |