| Conditions | 25 |
| Paths | 4096 |
| Total Lines | 24 |
| Code Lines | 23 |
| Lines | 24 |
| Ratio | 100 % |
| 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 |
||
| 79 | View Code Duplication | public function getTimeString($filetime, $now) { |
|
| 80 | $l = \OCP\Util::getL10N('ownnote'); |
||
| 81 | $difftime = $filetime->diff($now); |
||
| 82 | $years = $difftime->y; |
||
| 83 | $months = $difftime->m; |
||
| 84 | $days = $difftime->d; |
||
| 85 | $hours = $difftime->h; |
||
| 86 | $minutes = $difftime->i; |
||
| 87 | $seconds = $difftime->s; |
||
| 88 | $timestring = ""; |
||
| 89 | if ($timestring == "" && $years == 1) $timestring = str_replace('#', $years, $l->t("# year ago")); |
||
| 90 | if ($timestring == "" && $years > 0) $timestring = str_replace('#', $years, $l->t("# years ago")); |
||
| 91 | if ($timestring == "" && $months == 1) $timestring = str_replace('#', $months, $l->t("# month ago")); |
||
| 92 | if ($timestring == "" && $months > 0) $timestring = str_replace('#', $months, $l->t("# months ago")); |
||
| 93 | if ($timestring == "" && $days == 1) $timestring = str_replace('#', $days, $l->t("# day ago")); |
||
| 94 | if ($timestring == "" && $days > 0) $timestring = str_replace('#', $days, $l->t("# days ago")); |
||
| 95 | if ($timestring == "" && $hours == 1) $timestring = str_replace('#', $hours, $l->t("# hour ago")); |
||
| 96 | if ($timestring == "" && $hours > 0) $timestring = str_replace('#', $hours, $l->t("# hours ago")); |
||
| 97 | if ($timestring == "" && $minutes == 1) $timestring = str_replace('#', $minutes, $l->t("# minute ago")); |
||
| 98 | if ($timestring == "" && $minutes > 0) $timestring = str_replace('#', $minutes, $l->t("# minutes ago")); |
||
| 99 | if ($timestring == "" && $seconds == 1) $timestring = str_replace('#', $seconds, $l->t("# second ago")); |
||
| 100 | if ($timestring == "" && $seconds > 0) $timestring = str_replace('#', $seconds, $l->t("# seconds ago")); |
||
| 101 | return $timestring; |
||
| 102 | } |
||
| 103 | |||
| 125 | } |