| Conditions | 13 |
| Paths | 36 |
| Total Lines | 146 |
| Code Lines | 117 |
| Lines | 10 |
| Ratio | 6.85 % |
| 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 |
||
| 252 | function xhelp_default() |
||
| 253 | { |
||
| 254 | global $xoopsModuleConfig; |
||
| 255 | xoops_cp_header(); |
||
| 256 | //echo $oAdminButton->renderButtons('index'); |
||
| 257 | $indexAdmin = new ModuleAdmin(); |
||
| 258 | echo $indexAdmin->addNavigation('main.php'); |
||
| 259 | |||
| 260 | $displayName =& $xoopsModuleConfig['xhelp_displayName']; // Determines if username or real name is displayed |
||
| 261 | |||
| 262 | $stylePath = XHELP_BASE_URL.'/styles/xhelp.css'; |
||
| 263 | echo '<link rel="stylesheet" type="text/css" media="all" href="'.$stylePath.'" /><!--[if gte IE 5.5000]><script src="iepngfix.js" language="JavaScript" type="text/javascript"></script><![endif]-->'; |
||
| 264 | |||
| 265 | global $xoopsUser, $xoopsDB; |
||
| 266 | $hTickets =& xhelpGetHandler('ticket'); |
||
| 267 | $hStatus =& xhelpGetHandler('status'); |
||
| 268 | |||
| 269 | $crit = new Criteria('', ''); |
||
| 270 | $crit->setSort('description'); |
||
| 271 | $crit->setOrder('ASC'); |
||
| 272 | $statuses =& $hStatus->getObjects($crit); |
||
| 273 | $table_class = array('odd', 'even'); |
||
| 274 | echo "<table border='0' width='100%'>"; |
||
| 275 | echo "<tr><td width='50%' valign='top'>"; |
||
| 276 | echo "<div id='ticketInfo'>"; |
||
| 277 | echo "<table border='0' width='95%' cellspacing='1' class='outer'> |
||
| 278 | <tr><th colspan='2'>". _AM_XHELP_TEXT_TICKET_INFO ."</th></tr>"; |
||
| 279 | $class = "odd"; |
||
| 280 | $totalTickets = 0; |
||
| 281 | foreach($statuses as $status){ |
||
| 282 | $crit = new Criteria('status', $status->getVar('id')); |
||
| 283 | $numTickets =& $hTickets->getCount($crit); |
||
| 284 | $totalTickets += $numTickets; |
||
| 285 | |||
| 286 | echo "<tr class='".$class."'><td>".$status->getVar('description')."</td><td>".$numTickets."</td></tr>"; |
||
| 287 | if($class == "odd"){ |
||
| 288 | $class = "even"; |
||
| 289 | } else { |
||
| 290 | $class = "odd"; |
||
| 291 | } |
||
| 292 | } |
||
| 293 | echo "<tr class='foot'><td>"._AM_XHELP_TEXT_TOTAL_TICKETS."</td><td>".$totalTickets."</td></tr>"; |
||
| 294 | echo "</table></div><br />"; |
||
| 295 | |||
| 296 | $hStaff =& xhelpGetHandler('staff'); |
||
| 297 | $hResponses =& xhelpGetHandler('responses'); |
||
| 298 | echo "</td><td valign='top'>"; // Outer table |
||
| 299 | echo "<div id='timeSpent'>"; // Start inner top-left cell |
||
| 300 | echo "<table border='0' width='100%' cellspacing='1' class='outer'> |
||
| 301 | <tr><th colspan='2'>". _AM_XHELP_TEXT_RESPONSE_TIME ."</th></tr>"; |
||
| 302 | |||
| 303 | $sql = sprintf('SELECT u.uid, u.uname, u.name, (s.responseTime / s.ticketsResponded) as AvgResponseTime FROM %s u INNER JOIN %s s ON u.uid = s.uid WHERE ticketsResponded > 0 ORDER BY AvgResponseTime', $xoopsDB->prefix('users'), $xoopsDB->prefix('xhelp_staff')); |
||
| 304 | $ret = $xoopsDB->query($sql, MAX_STAFF_RESPONSETIME); |
||
| 305 | $i = 0; |
||
| 306 | View Code Duplication | while (list($uid, $uname, $name, $avgResponseTime) = $xoopsDB->fetchRow($ret)) { |
|
| 307 | $class = $table_class[$i % 2]; |
||
| 308 | echo "<tr class='$class'><td>". xhelpGetDisplayName($displayName, $name,$uname) ."</td><td align='right'>". xhelpFormatTime($avgResponseTime) ."</td></tr>"; |
||
| 309 | $i++; |
||
| 310 | } |
||
| 311 | echo "</table></div><br />"; // End inner top-left cell |
||
| 312 | echo "</td></tr><tr><td valign='top'>"; // End first, start second cell |
||
| 313 | |||
| 314 | //Get Calls Closed block |
||
| 315 | $sql = sprintf('SELECT SUM(callsClosed) FROM %s', $xoopsDB->prefix('xhelp_staff')); |
||
| 316 | $ret = $xoopsDB->query($sql); |
||
| 317 | if (list($totalStaffClosed) = $xoopsDB->fetchRow($ret)) { |
||
| 318 | if ($totalStaffClosed) { |
||
| 319 | $sql = sprintf('SELECT u.uid, u.uname, u.name, s.callsClosed FROM %s u INNER JOIN %s s ON u.uid = s.uid WHERE s.callsClosed > 0 ORDER BY s.callsClosed DESC', $xoopsDB->prefix('users'), $xoopsDB->prefix('xhelp_staff')); |
||
| 320 | $ret = $xoopsDB->query($sql, MAX_STAFF_CALLSCLOSED); |
||
| 321 | echo "<div id='callsClosed'>"; |
||
| 322 | echo "<table border='0' width='95%' cellspacing='1' class='outer'> |
||
| 323 | <tr><th colspan='2'>". _AM_XHELP_TEXT_TOP_CLOSERS ."</th></tr>"; |
||
| 324 | $i = 0; |
||
| 325 | while (list($uid, $uname, $name, $callsClosed) = $xoopsDB->fetchRow($ret)) { |
||
| 326 | $class = $table_class[$i % 2]; |
||
| 327 | echo "<tr class='$class'><td>". xhelpGetDisplayName($displayName, $name,$uname) ."</td><td align='right'>". $callsClosed. ' ('.round(($callsClosed/$totalStaffClosed)*100, 2) ."%)</td></tr>"; |
||
| 328 | $i++; |
||
| 329 | } |
||
| 330 | echo "</table></div><br />"; // End inner table top row |
||
| 331 | echo "</td><td valign='top'>"; // End top row of outer table |
||
| 332 | |||
| 333 | $sql = sprintf('SELECT u.uid, u.uname, u.name, (s.responseTime / s.ticketsResponded) as AvgResponseTime FROM %s u INNER JOIN %s s ON u.uid = s.uid WHERE ticketsResponded > 0 ORDER BY AvgResponseTime DESC', $xoopsDB->prefix('users'), $xoopsDB->prefix('xhelp_staff')); |
||
| 334 | $ret = $xoopsDB->query($sql, MAX_STAFF_RESPONSETIME); |
||
| 335 | echo "<div id='leastCallsClosed'>"; |
||
| 336 | echo "<table border='0' width='100%' cellspacing='1' class='outer'> |
||
| 337 | <tr><th colspan='2'>". _AM_XHELP_TEXT_RESPONSE_TIME_SLOW ."</th></tr>"; |
||
| 338 | $i = 0; |
||
| 339 | View Code Duplication | while (list($uid, $uname, $name, $avgResponseTime) = $xoopsDB->fetchRow($ret)) { |
|
| 340 | $class = $table_class[$i % 2]; |
||
| 341 | echo "<tr class='$class'><td>". xhelpGetDisplayName($displayName, $name,$uname) ."</td><td align='right'>". xhelpFormatTime($avgResponseTime) ."</td></tr>"; |
||
| 342 | $i++; |
||
| 343 | } |
||
| 344 | echo "</table></div>"; // End first cell, second row of inner table |
||
| 345 | } |
||
| 346 | } |
||
| 347 | echo "</td></tr></table><br />"; // End second cell, second row of inner table |
||
| 348 | |||
| 349 | $crit = new Criteria('state', '2', '<>', 's'); |
||
| 350 | $crit->setSort('priority'); |
||
| 351 | $crit->setOrder('ASC'); |
||
| 352 | $crit->setLimit(10); |
||
| 353 | $highPriority =& $hTickets->getObjects($crit); |
||
| 354 | $has_highPriority = (count($highPriority) > 0); |
||
| 355 | if($has_highPriority){ |
||
| 356 | echo "<div id='highPriority'>"; |
||
| 357 | echo "<table border='0' width='100%' cellspacing='1' class='outer'> |
||
| 358 | <tr><th colspan='8'>". _AM_XHELP_TEXT_HIGH_PRIORITY ."</th></tr>"; |
||
| 359 | echo "<tr class='head'><td>". _AM_XHELP_TEXT_PRIORITY ."</td><td>". _AM_XHELP_TEXT_ELAPSED ."</td><td>". _AM_XHELP_TEXT_STATUS ."</td><td>". _AM_XHELP_TEXT_SUBJECT ."</td><td>". _AM_XHELP_TEXT_DEPARTMENT ."</td><td>". _AM_XHELP_TEXT_OWNER ."</td><td>". _AM_XHELP_TEXT_LAST_UPDATED ."</td><td>". _AM_XHELP_TEXT_LOGGED_BY ."</td></tr>"; |
||
| 360 | $i = 0; |
||
| 361 | foreach($highPriority as $ticket){ |
||
| 362 | if($ticket->isOverdue()){ |
||
| 363 | $class = $table_class[$i % 2] . " overdue"; |
||
| 364 | } else { |
||
| 365 | $class = $table_class[$i % 2]; |
||
| 366 | } |
||
| 367 | $priority_url = "<img src='".XHELP_IMAGE_URL."/priority". $ticket->getVar('priority') .".png' alt='". $ticket->getVar('priority') ."' />"; |
||
| 368 | $subject_url = sprintf("<a href='".XHELP_BASE_URL."/ticket.php?id=". $ticket->getVar('id') ."' target='_BLANK'>%s</a>", $ticket->getVar('subject')); |
||
| 369 | if($dept = $ticket->getDepartment()){ |
||
| 370 | $dept_url = sprintf("<a href='".XHELP_BASE_URL."/index.php?op=staffViewAll&dept=". $dept->getVar('id') ."' target='_BLANK'>%s</a>", $dept->getVar('department')); |
||
| 371 | } else { |
||
| 372 | $dept_url = _AM_XHELP_TEXT_NO_DEPT; |
||
| 373 | } |
||
| 374 | if($ticket->getVar('ownership') <> 0){ |
||
| 375 | $owner_url = sprintf("<a href='".XOOPS_URL."/userinfo.php?uid=". $ticket->getVar('uid') ."' target='_BLANK'>%s</a>", xhelpGetUsername($ticket->getVar('ownership'), $displayName)); |
||
| 376 | } else { |
||
| 377 | $owner_url = _AM_XHELP_TEXT_NO_OWNER; |
||
| 378 | } |
||
| 379 | $user_url = sprintf("<a href='".XOOPS_URL."/userinfo.php?uid=". $ticket->getVar('uid') ."' target='_BLANK'>%s</a>", xhelpGetUsername($ticket->getVar('uid'), $displayName)); |
||
| 380 | echo "<tr class='$class'><td>". $priority_url ."</td> |
||
| 381 | <td>". $ticket->elapsed() ."</td> |
||
| 382 | <td>". xhelpGetStatus($ticket->getVar('status')) ."</td> |
||
| 383 | <td>". $subject_url ."</td> |
||
| 384 | <td>". $dept_url ."</td> |
||
| 385 | <td>". $owner_url ." </td> |
||
| 386 | <td>". $ticket->lastUpdated() ."</td> |
||
| 387 | <td>". $user_url ."</td> |
||
| 388 | </tr>"; |
||
| 389 | $i++; |
||
| 390 | } |
||
| 391 | echo "</table></div>"; |
||
| 392 | } |
||
| 393 | |||
| 394 | pathConfiguration(); |
||
| 395 | |||
| 396 | include_once "admin_footer.php"; |
||
| 397 | } |
||
| 398 | |||
| 456 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.