Conditions | 25 |
Paths | 4096 |
Total Lines | 24 |
Code Lines | 23 |
Lines | 12 |
Ratio | 50 % |
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 | 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 | View Code Duplication | if ($timestring == "" && $years == 1) $timestring = str_replace('#', $years, $l->t("# year ago")); |
|
|
|||
90 | View Code Duplication | if ($timestring == "" && $years > 0) $timestring = str_replace('#', $years, $l->t("# years ago")); |
|
91 | View Code Duplication | if ($timestring == "" && $months == 1) $timestring = str_replace('#', $months, $l->t("# month ago")); |
|
92 | View Code Duplication | if ($timestring == "" && $months > 0) $timestring = str_replace('#', $months, $l->t("# months ago")); |
|
93 | View Code Duplication | if ($timestring == "" && $days == 1) $timestring = str_replace('#', $days, $l->t("# day ago")); |
|
94 | View Code Duplication | if ($timestring == "" && $days > 0) $timestring = str_replace('#', $days, $l->t("# days ago")); |
|
95 | View Code Duplication | if ($timestring == "" && $hours == 1) $timestring = str_replace('#', $hours, $l->t("# hour ago")); |
|
96 | View Code Duplication | if ($timestring == "" && $hours > 0) $timestring = str_replace('#', $hours, $l->t("# hours ago")); |
|
97 | View Code Duplication | if ($timestring == "" && $minutes == 1) $timestring = str_replace('#', $minutes, $l->t("# minute ago")); |
|
98 | View Code Duplication | if ($timestring == "" && $minutes > 0) $timestring = str_replace('#', $minutes, $l->t("# minutes ago")); |
|
99 | View Code Duplication | if ($timestring == "" && $seconds == 1) $timestring = str_replace('#', $seconds, $l->t("# second ago")); |
|
100 | View Code Duplication | if ($timestring == "" && $seconds > 0) $timestring = str_replace('#', $seconds, $l->t("# seconds ago")); |
|
101 | return $timestring; |
||
102 | } |
||
103 | |||
125 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.