| Conditions | 12 |
| Paths | 60 |
| Total Lines | 89 |
| Code Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 28 | function b_hitcounter_show($options) |
||
| 29 | { |
||
| 30 | global $xoopsDB; |
||
| 31 | $block = []; |
||
| 32 | $myts = \MyTextSanitizer::getInstance(); |
||
|
|
|||
| 33 | $result = $xoopsDB->queryF('SELECT year, hits FROM ' . $xoopsDB->prefix('stats_year')); |
||
| 34 | $counter = 0; |
||
| 35 | $yearhits = []; |
||
| 36 | $cnt = 0; |
||
| 37 | while (list($year, $hits) = $xoopsDB->fetchRow($result)) { |
||
| 38 | $counter += $hits; // figure out total hits |
||
| 39 | |||
| 40 | $yearhits[$cnt]['year'] = $year; |
||
| 41 | $yearhits[$cnt]['counter'] = ''; |
||
| 42 | if (mb_strlen($hits) < 5) { |
||
| 43 | $hits = sprintf('%05d', $hits); |
||
| 44 | } |
||
| 45 | for ($i = 0, $iMax = mb_strlen($hits); $i < $iMax; ++$i) { |
||
| 46 | //the <img src> tag |
||
| 47 | $imgsrc = mb_substr($hits, $i, 1); |
||
| 48 | $yearhits[$cnt]['counter'] .= '<img src="' . XOOPS_URL . '/modules/statistics/assets/images/' . $imgsrc . '.gif" border = "0">'; |
||
| 49 | } |
||
| 50 | |||
| 51 | ++$cnt; |
||
| 52 | } |
||
| 53 | |||
| 54 | //number images are stored in the images directory |
||
| 55 | //and are numbered from 0.gif to 9.gif |
||
| 56 | //loop through the values of $counter and |
||
| 57 | //use the strlen function to check the length of $counter |
||
| 58 | $cnt_graphic = ''; |
||
| 59 | if (mb_strlen($counter) < 5) { |
||
| 60 | $counter = sprintf('%05d', $counter); |
||
| 61 | } |
||
| 62 | for ($i = 0, $iMax = mb_strlen($counter); $i < $iMax; ++$i) { |
||
| 63 | //the <img src> tag |
||
| 64 | $imgsrc = mb_substr($counter, $i, 1); |
||
| 65 | $cnt_graphic .= '<img src="' . XOOPS_URL . '/modules/statistics/assets/images/' . $imgsrc . '.gif" border = "0">'; |
||
| 66 | } |
||
| 67 | |||
| 68 | if ('1' == $options[1]) { // check to see if we should show the blocked hits |
||
| 69 | $result = $xoopsDB->queryF('SELECT year, hits FROM ' . $xoopsDB->prefix('stats_blockedyear')); |
||
| 70 | $bcounter = 0; |
||
| 71 | $byearhits = []; |
||
| 72 | $cnt = 0; |
||
| 73 | while (list($year, $hits) = $xoopsDB->fetchRow($result)) { |
||
| 74 | $bcounter += $hits; // figure out total hits |
||
| 75 | |||
| 76 | $byearhits[$cnt]['year'] = $year; |
||
| 77 | $byearhits[$cnt]['counter'] = ''; |
||
| 78 | if (mb_strlen($hits) < 5) { |
||
| 79 | $hits = sprintf('%05d', $hits); |
||
| 80 | } |
||
| 81 | for ($i = 0, $iMax = mb_strlen($hits); $i < $iMax; ++$i) { |
||
| 82 | //the <img src> tag |
||
| 83 | $imgsrc = mb_substr($hits, $i, 1); |
||
| 84 | $byearhits[$cnt]['counter'] .= '<img src="' . XOOPS_URL . '/modules/statistics/assets/images/' . $imgsrc . '.gif" border = "0">'; |
||
| 85 | } |
||
| 86 | |||
| 87 | ++$cnt; |
||
| 88 | } |
||
| 89 | |||
| 90 | //number images are stored in the images directory |
||
| 91 | //and are numbered from 0.gif to 9.gif |
||
| 92 | //loop through the values of $counter and |
||
| 93 | //use the strlen function to check the length of $counter |
||
| 94 | $bcnt_graphic = ''; |
||
| 95 | if (mb_strlen($bcounter) < 5) { |
||
| 96 | $bcounter = sprintf('%05d', $bcounter); |
||
| 97 | } |
||
| 98 | for ($i = 0, $iMax = mb_strlen($bcounter); $i < $iMax; ++$i) { |
||
| 99 | //the <img src> tag |
||
| 100 | $imgsrc = mb_substr($bcounter, $i, 1); |
||
| 101 | $bcnt_graphic .= '<img src="' . XOOPS_URL . '/modules/statistics/assets/images/' . $imgsrc . '.gif" border = "0">'; |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | $block['display'] = $options[0]; |
||
| 106 | $block['displayblockedhits'] = $options[1]; |
||
| 107 | $block['counterhead'] = B_STATS_CNTHEAD; |
||
| 108 | $block['bcounterhead'] = B_STATS_BLOCKED_CNTHEAD; |
||
| 109 | $block['yearhead'] = B_STATS_YRHEAD; |
||
| 110 | $block['byearhead'] = B_STATS_BLOCKED_YRHEAD; |
||
| 111 | $block['counter'] = $cnt_graphic; |
||
| 112 | $block['bcounter'] = $bcnt_graphic; |
||
| 113 | $block['yearhits'] = $yearhits; |
||
| 114 | $block['byearhits'] = $byearhits; |
||
| 115 | |||
| 116 | return $block; |
||
| 117 | } |
||
| 147 |