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 |
||
186 | public static function formatTimestamp($time, $format = 'l', $timeoffset = null) |
||
187 | { |
||
188 | global $xoopsConfig, $xoopsUser; |
||
189 | |||
190 | $format_copy = $format; |
||
191 | $format = strtolower($format); |
||
192 | |||
193 | if ($format === 'rss' || $format === 'r') { |
||
194 | $TIME_ZONE = ''; |
||
195 | if (isset($GLOBALS['xoopsConfig']['server_TZ'])) { |
||
196 | $server_TZ = abs((int)($GLOBALS['xoopsConfig']['server_TZ'] * 3600.0)); |
||
197 | $prefix = ($GLOBALS['xoopsConfig']['server_TZ'] < 0) ? ' -' : ' +'; |
||
198 | $TIME_ZONE = $prefix . date('Hi', $server_TZ); |
||
|
|||
199 | } |
||
200 | $date = gmdate('D, d M Y H:i:s', (int)$time) . $TIME_ZONE; |
||
201 | |||
202 | return $date; |
||
203 | } |
||
204 | |||
205 | if (($format === 'elapse' || $format === 'e') && $time < time()) { |
||
206 | $elapse = time() - $time; |
||
207 | if ($days = floor($elapse / (24 * 3600))) { |
||
208 | $num = $days > 1 ? sprintf(_DAYS, $days) : _DAY; |
||
209 | } elseif ($hours = floor(($elapse % (24 * 3600)) / 3600)) { |
||
210 | $num = $hours > 1 ? sprintf(_HOURS, $hours) : _HOUR; |
||
211 | } elseif ($minutes = floor(($elapse % 3600) / 60)) { |
||
212 | $num = $minutes > 1 ? sprintf(_MINUTES, $minutes) : _MINUTE; |
||
213 | } else { |
||
214 | $seconds = $elapse % 60; |
||
215 | $num = $seconds > 1 ? sprintf(_SECONDS, $seconds) : _SECOND; |
||
216 | } |
||
217 | $ret = sprintf(_ELAPSE, $num); |
||
218 | |||
219 | return $ret; |
||
220 | } |
||
221 | // disable user timezone calculation and use default timezone, |
||
222 | // for cache consideration |
||
223 | if ($timeoffset === null) { |
||
224 | $timeoffset = ($xoopsConfig['default_TZ'] == '') ? '0.0' : $xoopsConfig['default_TZ']; |
||
225 | } |
||
226 | $usertimestamp = xoops_getUserTimestamp($time, $timeoffset); |
||
227 | switch ($format) { |
||
228 | case 's': |
||
229 | $datestring = _SHORTDATESTRING; |
||
230 | break; |
||
231 | |||
232 | case 'm': |
||
233 | $datestring = _MEDIUMDATESTRING; |
||
234 | break; |
||
235 | |||
236 | case 'mysql': |
||
237 | $datestring = 'Y-m-d H:i:s'; |
||
238 | break; |
||
239 | |||
240 | case 'l': |
||
241 | $datestring = _DATESTRING; |
||
242 | break; |
||
243 | |||
244 | case 'c': |
||
245 | case 'custom': |
||
246 | static $current_timestamp, $today_timestamp, $monthy_timestamp; |
||
247 | if (!isset($current_timestamp)) { |
||
248 | $current_timestamp = xoops_getUserTimestamp(time(), $timeoffset); |
||
249 | } |
||
250 | if (!isset($today_timestamp)) { |
||
251 | $today_timestamp = mktime(0, 0, 0, date('m', $current_timestamp), date('d', $current_timestamp), date('Y', $current_timestamp)); |
||
252 | } |
||
253 | |||
254 | if (abs($elapse_today = $usertimestamp - $today_timestamp) < 24 * 60 * 60) { |
||
255 | $datestring = ($elapse_today > 0) ? _TODAY : _YESTERDAY; |
||
256 | } else { |
||
257 | if (!isset($monthy_timestamp)) { |
||
258 | $monthy_timestamp[0] = mktime(0, 0, 0, 0, 0, date('Y', $current_timestamp)); |
||
259 | $monthy_timestamp[1] = mktime(0, 0, 0, 0, 0, date('Y', $current_timestamp) + 1); |
||
260 | } |
||
261 | $datestring = _YEARMONTHDAY; |
||
262 | if ($usertimestamp >= $monthy_timestamp[0] && $usertimestamp < $monthy_timestamp[1]) { |
||
263 | $datestring = _MONTHDAY; |
||
264 | } |
||
265 | } |
||
266 | break; |
||
267 | |||
268 | default: |
||
269 | $datestring = _DATESTRING; |
||
270 | if ($format != '') { |
||
271 | $datestring = $format_copy; |
||
272 | } |
||
273 | break; |
||
274 | } |
||
275 | |||
276 | return ucfirst(date($datestring, $usertimestamp)); |
||
277 | } |
||
317 |