| Conditions | 10 |
| Paths | 40 |
| Total Lines | 70 |
| Code Lines | 47 |
| Lines | 5 |
| Ratio | 7.14 % |
| 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 |
||
| 44 | function b_donations_donors_show($options) |
||
| 45 | { |
||
| 46 | global $xoopsDB; |
||
| 47 | |||
| 48 | $tr_config = configInfo(); |
||
| 49 | //determine the currency |
||
| 50 | $PP_CURR_CODE = explode('|', $tr_config['pp_curr_code']); // [USD,GBP,JPY,CAD,EUR] |
||
| 51 | $PP_CURR_CODE = $PP_CURR_CODE[0]; |
||
| 52 | $currencySign = defineCurrency($PP_CURR_CODE); |
||
| 53 | |||
| 54 | $dmshowdate = $options[1]; |
||
| 55 | $dmshowamt = $options[2]; |
||
| 56 | $block = array(); |
||
| 57 | $swingd = $tr_config['swing_day']; |
||
| 58 | |||
| 59 | if (($swingd < 0) or ($swingd > 31)) { |
||
| 60 | $swingd = 6; |
||
| 61 | } |
||
| 62 | |||
| 63 | if (date('d') >= $swingd) { |
||
| 64 | $query_Recordset1 = "SELECT custom AS muser_id, option_selection1 as showname, DATE_FORMAT(payment_date, '%b %e') AS date, CONCAT('" . $currencySign . "',SUM(mc_gross)) AS amt FROM " . $xoopsDB->prefix('donations_transactions') . " WHERE (payment_date >= DATE_FORMAT(NOW(),'%Y-%m-" . $swingd . "')) GROUP BY txn_id ORDER BY payment_date DESC"; |
||
| 65 | } else { |
||
| 66 | $query_Recordset1 = "SELECT custom AS muser_id, option_selection1 as showname, DATE_FORMAT(payment_date, '%b-%e') AS date, CONCAT('" . $currencySign . "',SUM(mc_gross)) AS amt FROM " . $xoopsDB->prefix('donations_transactions') . " WHERE (payment_date < DATE_FORMAT(NOW(), '%Y-%m-" . $swingd . "')) AND payment_date > DATE_FORMAT(SUBDATE(NOW(),INTERVAL " . $swingd . " DAY), '%Y-%m-" . $swingd . "') GROUP BY txn_id ORDER BY payment_date DESC"; |
||
| 67 | } |
||
| 68 | |||
| 69 | $Recordset1 = $xoopsDB->query($query_Recordset1); |
||
| 70 | $totalRows_Recordset1 = $xoopsDB->getRowsNum($Recordset1); |
||
| 71 | |||
| 72 | $ROWS_DONATORS = ''; |
||
| 73 | // Fill out the donators table tag |
||
| 74 | while (false!=($row_Recordset1 = $xoopsDB->fetchArray($Recordset1))) { |
||
| 75 | if ($row_Recordset1['amt'] > $currencySign . '0') { |
||
| 76 | $ROWS_DONATORS .= '<tr>'; |
||
| 77 | $ROWS_DONATORS .= "<td style=\"font-weight: bold;\"> "; |
||
| 78 | |||
| 79 | $muser_id = $row_Recordset1['muser_id']; |
||
| 80 | View Code Duplication | if (strcmp($row_Recordset1['showname'], 'Yes') == 0 && ($userfoin = mgetUserInfo($muser_id))) { |
|
| 81 | $ROWS_DONATORS .= "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userfoin->getVar('uid') . "'>" . xdshorten($userfoin->getVar('uname')) . "</a>\n"; |
||
| 82 | } else { |
||
| 83 | $ROWS_DONATORS .= _MB_DON_ANONYMOUS_SHORT; |
||
| 84 | } |
||
| 85 | |||
| 86 | $ROWS_DONATORS .= "</td>\n"; |
||
| 87 | if ($dmshowamt) { |
||
| 88 | $ROWS_DONATORS .= "<td style=\"width: 2px;\"> </td>\n"; |
||
| 89 | $ROWS_DONATORS .= "<td style=\"width: 55px; font-weight: bold;\"> "; |
||
| 90 | $ROWS_DONATORS .= $row_Recordset1['amt']; |
||
| 91 | $ROWS_DONATORS .= "</td>\n"; |
||
| 92 | } |
||
| 93 | if ($dmshowdate) { |
||
| 94 | $ROWS_DONATORS .= "<td style=\"width: 2px;\"> </td>\n"; |
||
| 95 | $ROWS_DONATORS .= "<td style=\"font-weight: bold;\"> "; |
||
| 96 | $ROWS_DONATORS .= $row_Recordset1['date']; |
||
| 97 | $ROWS_DONATORS .= "</td>\n"; |
||
| 98 | } |
||
| 99 | $ROWS_DONATORS .= "</tr>\n"; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | // Ok, output the page |
||
| 104 | |||
| 105 | $block['showamt'] = $dmshowamt; |
||
| 106 | $block['showdate'] = $dmshowdate; |
||
| 107 | $block['list'] = $ROWS_DONATORS; |
||
| 108 | $block['amount'] = _MB_DON_AMOUNT; |
||
| 109 | $block['date'] = _MB_DON_DATE; |
||
| 110 | $block['name'] = _MB_DON_NAME; |
||
| 111 | |||
| 112 | return $block; |
||
| 113 | } |
||
| 114 | |||
| 165 |
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.