| Conditions | 17 |
| Paths | 17 |
| Total Lines | 54 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 28 | public static function distanceOfTimeInWords($fromTime, $toTime = 0, $showLessThanAMinute = false) |
||
| 29 | { |
||
| 30 | $distanceInSeconds = round(abs($toTime - strtotime($fromTime))); |
||
| 31 | $distanceInMinutes = round($distanceInSeconds / 60); |
||
| 32 | |||
| 33 | if ($distanceInMinutes <= 1) { |
||
| 34 | if (!$showLessThanAMinute) { |
||
| 35 | return ($distanceInMinutes == 0) ? 'less than a minute' : '1 minute'; |
||
| 36 | } else { |
||
| 37 | if ($distanceInSeconds < 5) { |
||
| 38 | return 'less than 5 seconds'; |
||
| 39 | } |
||
| 40 | if ($distanceInSeconds < 10) { |
||
| 41 | return 'less than 10 seconds'; |
||
| 42 | } |
||
| 43 | if ($distanceInSeconds < 20) { |
||
| 44 | return 'less than 20 seconds'; |
||
| 45 | } |
||
| 46 | if ($distanceInSeconds < 40) { |
||
| 47 | return 'about half a minute'; |
||
| 48 | } |
||
| 49 | if ($distanceInSeconds < 60) { |
||
| 50 | return 'less than a minute'; |
||
| 51 | } |
||
| 52 | |||
| 53 | return '1 minute'; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | if ($distanceInMinutes < 45) { |
||
| 57 | return $distanceInMinutes . ' minutes'; |
||
| 58 | } |
||
| 59 | if ($distanceInMinutes < 90) { |
||
| 60 | return 'about 1 hour'; |
||
| 61 | } |
||
| 62 | if ($distanceInMinutes < 1440) { |
||
| 63 | return 'about ' . round(floatval($distanceInMinutes) / 60.0) . ' hours'; |
||
| 64 | } |
||
| 65 | if ($distanceInMinutes < 2880) { |
||
| 66 | return '1 day'; |
||
| 67 | } |
||
| 68 | if ($distanceInMinutes < 43200) { |
||
| 69 | return 'about ' . round(floatval($distanceInMinutes) / 1440) . ' days'; |
||
| 70 | } |
||
| 71 | if ($distanceInMinutes < 86400) { |
||
| 72 | return 'about 1 month'; |
||
| 73 | } |
||
| 74 | if ($distanceInMinutes < 525600) { |
||
| 75 | return round(floatval($distanceInMinutes) / 43200) . ' months'; |
||
| 76 | } |
||
| 77 | if ($distanceInMinutes < 1051199) { |
||
| 78 | return 'about 1 year'; |
||
| 79 | } |
||
| 80 | |||
| 81 | return 'over ' . round(floatval($distanceInMinutes) / 525600) . ' years'; |
||
| 82 | } |
||
| 159 |