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