| Conditions | 8 |
| Paths | 24 |
| Total Lines | 56 |
| Code Lines | 39 |
| 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 declare(strict_types=1); |
||
| 32 | function b_marquee_tplleaguestats($limit, $dateFormat, $itemsSize) |
||
| 33 | { |
||
| 34 | // require_once XOOPS_ROOT_PATH . '/modules/marquee/class/Utility.php'; |
||
| 35 | //######################## SETTINGS ###################### |
||
| 36 | $displaySeason = false; // display season name? |
||
| 37 | $hour = 1; // GMT+1 -> var = 1 |
||
| 38 | $useItemSize = false; // use marquee $itemsize value? |
||
| 39 | $overwriteLimit = true; // overwrite marquee's limit settings? |
||
| 40 | $newLimit = 6; // new limit (valid only if |
||
| 41 | // overwrite_limit_settings = true) |
||
| 42 | $overwriteDateformat = true; // overwrite marquee's dateformat? |
||
| 43 | $newDateformat = 'd/m/Y'; // new dateformat (valid only if |
||
| 44 | // overwrite_dateformat_settings=true) |
||
| 45 | //######################## SETTINGS ###################### |
||
| 46 | global $xoopsDB; |
||
| 47 | if ($overwriteLimit) { |
||
|
|
|||
| 48 | $limit = $newLimit; |
||
| 49 | } |
||
| 50 | if ($overwriteDateformat) { |
||
| 51 | $dateFormat = $newDateformat; |
||
| 52 | } |
||
| 53 | $block = []; |
||
| 54 | $myts = \MyTextSanitizer::getInstance(); |
||
| 55 | $sql = 'SELECT H.OpponentName as home, A.OpponentName as away, M.LeagueMatchHomeGoals as home_p, M.LeagueMatchAwayGoals as away_p, |
||
| 56 | M.LeagueMatchDate as date, S.SeasonName as season |
||
| 57 | FROM ' . $xoopsDB->prefix('tplls_leaguematches') . ' M |
||
| 58 | LEFT JOIN ' . $xoopsDB->prefix('tplls_opponents') . ' AS H ON M.LeagueMatchHomeID = H.OpponentID |
||
| 59 | LEFT JOIN ' . $xoopsDB->prefix('tplls_opponents') . ' AS A ON M.LeagueMatchAwayID = A.OpponentID |
||
| 60 | LEFT JOIN ' . $xoopsDB->prefix('tplls_seasonnames') . " AS S ON M.LeagueMatchSeasonID = S.SeasonID |
||
| 61 | ORDER BY M.LeagueMatchDate DESC |
||
| 62 | LIMIT 0,$limit"; |
||
| 63 | $result = $xoopsDB->query($sql); |
||
| 64 | if (!$xoopsDB->isResultSet($result)) { |
||
| 65 | throw new \RuntimeException( |
||
| 66 | \sprintf(_DB_QUERY_ERROR, $sql) . $xoopsDB->error(), E_USER_ERROR); |
||
| 67 | } |
||
| 68 | while (false !== ($myrow = $xoopsDB->fetchArray($result))) { |
||
| 69 | $title = htmlspecialchars($myrow['home'], ENT_QUOTES | ENT_HTML5) . ' - ' . htmlspecialchars($myrow['away'], ENT_QUOTES | ENT_HTML5) . ' ' . htmlspecialchars($myrow['home_p'], ENT_QUOTES | ENT_HTML5) . '-' . htmlspecialchars($myrow['away_p'], ENT_QUOTES | ENT_HTML5); |
||
| 70 | if ($useItemSize && $itemsSize > 0) { |
||
| 71 | $title = xoops_substr($title, 0, $itemsSize + 3); |
||
| 72 | } |
||
| 73 | $arrDate = explode('-', $myrow['date']); |
||
| 74 | $season = ''; |
||
| 75 | if ($displaySeason) { |
||
| 76 | $season = $myrow['season']; |
||
| 77 | } |
||
| 78 | $block[] = [ |
||
| 79 | 'date' => formatTimestamp(mktime($hour, 0, 0, $arrDate[1], $arrDate[2], $arrDate[0]), $dateFormat), |
||
| 80 | 'category' => $season, |
||
| 81 | 'author' => '', |
||
| 82 | 'title' => $title, |
||
| 83 | 'link' => '<a href="' . XOOPS_URL . '/modules/tplleaguestats">' . $title . '</a>', |
||
| 84 | ]; |
||
| 85 | } |
||
| 86 | |||
| 87 | return $block; |
||
| 88 | } |
||
| 89 |