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