| Conditions | 31 |
| Paths | 173 |
| Total Lines | 91 |
| Code Lines | 63 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 129 | public static function formatTimestamp($time, $format = 'l', $timeoffset = null) |
||
| 130 | { |
||
| 131 | global $xoopsConfig, $xoopsUser; |
||
| 132 | |||
| 133 | $format_copy = $format; |
||
| 134 | $format = strtolower($format); |
||
| 135 | |||
| 136 | if ($format === 'rss' || $format === 'r') { |
||
| 137 | $TIME_ZONE = ''; |
||
| 138 | if (isset($GLOBALS['xoopsConfig']['server_TZ'])) { |
||
| 139 | $server_TZ = abs((int)($GLOBALS['xoopsConfig']['server_TZ'] * 3600.0)); |
||
| 140 | $prefix = ($GLOBALS['xoopsConfig']['server_TZ'] < 0) ? ' -' : ' +'; |
||
| 141 | $TIME_ZONE = $prefix . date('Hi', $server_TZ); |
||
| 142 | } |
||
| 143 | $date = gmdate('D, d M Y H:i:s', (int)$time) . $TIME_ZONE; |
||
| 144 | |||
| 145 | return $date; |
||
| 146 | } |
||
| 147 | |||
| 148 | if (($format === 'elapse' || $format === 'e') && $time < time()) { |
||
| 149 | $elapse = time() - $time; |
||
| 150 | if ($days = floor($elapse / (24 * 3600))) { |
||
| 151 | $num = $days > 1 ? sprintf(_DAYS, $days) : _DAY; |
||
| 152 | } elseif ($hours = floor(($elapse % (24 * 3600)) / 3600)) { |
||
| 153 | $num = $hours > 1 ? sprintf(_HOURS, $hours) : _HOUR; |
||
| 154 | } elseif ($minutes = floor(($elapse % 3600) / 60)) { |
||
| 155 | $num = $minutes > 1 ? sprintf(_MINUTES, $minutes) : _MINUTE; |
||
| 156 | } else { |
||
| 157 | $seconds = $elapse % 60; |
||
| 158 | $num = $seconds > 1 ? sprintf(_SECONDS, $seconds) : _SECOND; |
||
| 159 | } |
||
| 160 | $ret = sprintf(_ELAPSE, $num); |
||
| 161 | |||
| 162 | return $ret; |
||
| 163 | } |
||
| 164 | // disable user timezone calculation and use default timezone, |
||
| 165 | // for cache consideration |
||
| 166 | if ($timeoffset === null) { |
||
| 167 | $timeoffset = ($xoopsConfig['default_TZ'] == '') ? '0.0' : $xoopsConfig['default_TZ']; |
||
| 168 | } |
||
| 169 | $usertimestamp = xoops_getUserTimestamp($time, $timeoffset); |
||
| 170 | switch ($format) { |
||
| 171 | case 's': |
||
| 172 | $datestring = _SHORTDATESTRING; |
||
| 173 | break; |
||
| 174 | |||
| 175 | case 'm': |
||
| 176 | $datestring = _MEDIUMDATESTRING; |
||
| 177 | break; |
||
| 178 | |||
| 179 | case 'mysql': |
||
| 180 | $datestring = 'Y-m-d H:i:s'; |
||
| 181 | break; |
||
| 182 | |||
| 183 | case 'l': |
||
| 184 | $datestring = _DATESTRING; |
||
| 185 | break; |
||
| 186 | |||
| 187 | case 'c': |
||
| 188 | case 'custom': |
||
| 189 | static $current_timestamp, $today_timestamp, $monthy_timestamp; |
||
| 190 | if (!isset($current_timestamp)) { |
||
| 191 | $current_timestamp = xoops_getUserTimestamp(time(), $timeoffset); |
||
| 192 | } |
||
| 193 | if (!isset($today_timestamp)) { |
||
| 194 | $today_timestamp = mktime(0, 0, 0, date('m', $current_timestamp), date('d', $current_timestamp), date('Y', $current_timestamp)); |
||
| 195 | } |
||
| 196 | |||
| 197 | if (abs($elapse_today = $usertimestamp - $today_timestamp) < 24 * 60 * 60) { |
||
| 198 | $datestring = ($elapse_today > 0) ? _TODAY : _YESTERDAY; |
||
| 199 | } else { |
||
| 200 | if (!isset($monthy_timestamp)) { |
||
| 201 | $monthy_timestamp[0] = mktime(0, 0, 0, 0, 0, date('Y', $current_timestamp)); |
||
| 202 | $monthy_timestamp[1] = mktime(0, 0, 0, 0, 0, date('Y', $current_timestamp) + 1); |
||
| 203 | } |
||
| 204 | $datestring = _YEARMONTHDAY; |
||
| 205 | if ($usertimestamp >= $monthy_timestamp[0] && $usertimestamp < $monthy_timestamp[1]) { |
||
| 206 | $datestring = _MONTHDAY; |
||
| 207 | } |
||
| 208 | } |
||
| 209 | break; |
||
| 210 | |||
| 211 | default: |
||
| 212 | $datestring = _DATESTRING; |
||
| 213 | if ($format != '') { |
||
| 214 | $datestring = $format_copy; |
||
| 215 | } |
||
| 216 | break; |
||
| 217 | } |
||
| 218 | |||
| 219 | return ucfirst(date($datestring, $usertimestamp)); |
||
| 220 | } |
||
| 275 |