| Conditions | 14 | 
| Paths | 253 | 
| Total Lines | 170 | 
| Code Lines | 114 | 
| 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  | 
            ||
| 59 | function list_blocks()  | 
            ||
| 60 | { | 
            ||
| 61 | global $block_arr, $xoopsModule;  | 
            ||
| 62 | |||
| 63 | // cachetime options  | 
            ||
| 64 | $cachetimes = [  | 
            ||
| 65 | '0' => _NOCACHE,  | 
            ||
| 66 | '30' => sprintf(_SECONDS, 30),  | 
            ||
| 67 | '60' => _MINUTE,  | 
            ||
| 68 | '300' => sprintf(_MINUTES, 5),  | 
            ||
| 69 | '1800' => sprintf(_MINUTES, 30),  | 
            ||
| 70 | '3600' => _HOUR,  | 
            ||
| 71 | '18000' => sprintf(_HOURS, 5),  | 
            ||
| 72 | '86400' => _DAY,  | 
            ||
| 73 | '259200' => sprintf(_DAYS, 3),  | 
            ||
| 74 | '604800' => _WEEK,  | 
            ||
| 75 | '2592000' => _MONTH  | 
            ||
| 76 | ];  | 
            ||
| 77 | |||
| 78 | // displaying TH  | 
            ||
| 79 |     Smartfaq\Utility::collapsableBar('toptable', 'toptableicon'); | 
            ||
| 80 | echo "<img id='toptableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt=''></a> " . _AM_SF_BLOCKS . '</h3>';  | 
            ||
| 81 | echo "<div id='toptable'>";  | 
            ||
| 82 | echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . _AM_SF_BLOCKSTXT . '</span>';  | 
            ||
| 83 | |||
| 84 | echo "  | 
            ||
| 85 | <form action='admin.php' name='blockadmin' method='post'>  | 
            ||
| 86 | <table width='100%' class='outer' cellpadding='4' cellspacing='1'>  | 
            ||
| 87 | <tr valign='middle'>  | 
            ||
| 88 | <th>" . _AM_TITLE . "</th>  | 
            ||
| 89 | <th align='center' nowrap='nowrap'>" . _AM_SF_POSITION . "</th>  | 
            ||
| 90 | <th align='center'>" . _AM_WEIGHT . "</th>  | 
            ||
| 91 | <th align='center'>" . _AM_VISIBLEIN . "</th>  | 
            ||
| 92 | <th align='center'>" . _AM_BCACHETIME . "</th>  | 
            ||
| 93 | <th align='center'>" . _AM_ACTION . "</th>  | 
            ||
| 94 | </tr>\n";  | 
            ||
| 95 | |||
| 96 | // blocks displaying loop  | 
            ||
| 97 | $class = 'even';  | 
            ||
| 98 |     foreach (array_keys($block_arr) as $i) { | 
            ||
| 99 | $sseln = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = '';  | 
            ||
| 100 | |||
| 101 |         $weight     = $block_arr[$i]->getVar('weight'); | 
            ||
| 102 |         $title      = $block_arr[$i]->getVar('title'); | 
            ||
| 103 |         $name       = $block_arr[$i]->getVar('name'); | 
            ||
| 104 |         $bcachetime = $block_arr[$i]->getVar('bcachetime'); | 
            ||
| 105 |         $bid        = $block_arr[$i]->getVar('bid'); | 
            ||
| 106 | |||
| 107 | // visible and side  | 
            ||
| 108 |         if (1 != $block_arr[$i]->getVar('visible')) { | 
            ||
| 109 | $sseln = " checked style='background-color:#FF0000;'";  | 
            ||
| 110 |         } else { | 
            ||
| 111 |             switch ($block_arr[$i]->getVar('side')) { | 
            ||
| 112 | default:  | 
            ||
| 113 | case XOOPS_SIDEBLOCK_LEFT:  | 
            ||
| 114 | $ssel0 = " checked style='background-color:#00FF00;'";  | 
            ||
| 115 | break;  | 
            ||
| 116 | case XOOPS_SIDEBLOCK_RIGHT:  | 
            ||
| 117 | $ssel1 = " checked style='background-color:#00FF00;'";  | 
            ||
| 118 | break;  | 
            ||
| 119 | case XOOPS_CENTERBLOCK_LEFT:  | 
            ||
| 120 | $ssel2 = " checked style='background-color:#00FF00;'";  | 
            ||
| 121 | break;  | 
            ||
| 122 | case XOOPS_CENTERBLOCK_RIGHT:  | 
            ||
| 123 | $ssel4 = " checked style='background-color:#00FF00;'";  | 
            ||
| 124 | break;  | 
            ||
| 125 | case XOOPS_CENTERBLOCK_CENTER:  | 
            ||
| 126 | $ssel3 = " checked style='background-color:#00FF00;'";  | 
            ||
| 127 | break;  | 
            ||
| 128 | }  | 
            ||
| 129 | }  | 
            ||
| 130 | |||
| 131 | // bcachetime  | 
            ||
| 132 | $cachetime_options = '';  | 
            ||
| 133 |         foreach ($cachetimes as $cachetime => $cachetime_name) { | 
            ||
| 134 |             if ($bcachetime == $cachetime) { | 
            ||
| 135 | $cachetime_options .= "<option value='$cachetime' selected>$cachetime_name</option>\n";  | 
            ||
| 136 |             } else { | 
            ||
| 137 | $cachetime_options .= "<option value='$cachetime'>$cachetime_name</option>\n";  | 
            ||
| 138 | }  | 
            ||
| 139 | }  | 
            ||
| 140 | |||
| 141 | // target modules  | 
            ||
| 142 | $db = \XoopsDatabaseFactory::getDatabaseConnection();  | 
            ||
| 143 |         $result        = $db->query('SELECT module_id FROM ' . $db->prefix('block_module_link') . " WHERE block_id='$bid'"); | 
            ||
| 144 | $selected_mids = [];  | 
            ||
| 145 |         while (list($selected_mid) = $db->fetchRow($result)) { | 
            ||
| 146 | $selected_mids[] = (int)$selected_mid;  | 
            ||
| 147 | }  | 
            ||
| 148 | /** @var XoopsModuleHandler $moduleHandler */  | 
            ||
| 149 |         $moduleHandler = xoops_getHandler('module'); | 
            ||
| 150 |         $criteria      = new \CriteriaCompo(new \Criteria('hasmain', 1)); | 
            ||
| 151 |         $criteria->add(new \Criteria('isactive', 1)); | 
            ||
| 152 | $module_list = $moduleHandler->getList($criteria);  | 
            ||
| 153 | $module_list[-1] = _AM_TOPPAGE;  | 
            ||
| 154 | $module_list[0] = _AM_ALLPAGES;  | 
            ||
| 155 | ksort($module_list);  | 
            ||
| 156 | $module_options = '';  | 
            ||
| 157 | $myts = \MyTextSanitizer::getInstance();  | 
            ||
| 158 |         foreach ($module_list as $mid => $mname) { | 
            ||
| 159 |             if (in_array($mid, $selected_mids)) { | 
            ||
| 160 | $module_options .= "<option value='$mid' selected>" . $myts->displayTarea($mname) . "</option>\n";  | 
            ||
| 161 |             } else { | 
            ||
| 162 | $module_options .= "<option value='$mid'>" . $myts->displayTarea($mname) . "</option>\n";  | 
            ||
| 163 | }  | 
            ||
| 164 | }  | 
            ||
| 165 | |||
| 166 | // displaying part  | 
            ||
| 167 | echo "  | 
            ||
| 168 | <tr valign='middle'>  | 
            ||
| 169 | <td class='$class'>  | 
            ||
| 170 | $name  | 
            ||
| 171 | <br>  | 
            ||
| 172 | <input type='text' name='title[$bid]' value='$title' size='20'>  | 
            ||
| 173 | </td>  | 
            ||
| 174 | <td class='$class' align='center' nowrap='nowrap'>  | 
            ||
| 175 | <input type='radio' name='side[$bid]' value='"  | 
            ||
| 176 | . XOOPS_SIDEBLOCK_LEFT  | 
            ||
| 177 | . "'$ssel0>-<input type='radio' name='side[$bid]' value='"  | 
            ||
| 178 | . XOOPS_CENTERBLOCK_LEFT  | 
            ||
| 179 | . "'$ssel2><input type='radio' name='side[$bid]' value='"  | 
            ||
| 180 | . XOOPS_CENTERBLOCK_CENTER  | 
            ||
| 181 | . "'$ssel3><input type='radio' name='side[$bid]' value='"  | 
            ||
| 182 | . XOOPS_CENTERBLOCK_RIGHT  | 
            ||
| 183 | . "'$ssel4>-<input type='radio' name='side[$bid]' value='"  | 
            ||
| 184 | . XOOPS_SIDEBLOCK_RIGHT  | 
            ||
| 185 | . "'$ssel1>  | 
            ||
| 186 | <br>  | 
            ||
| 187 | <br>  | 
            ||
| 188 | <input type='radio' name='side[$bid]' value='-1'$sseln>  | 
            ||
| 189 | "  | 
            ||
| 190 | . _NONE  | 
            ||
| 191 | . "  | 
            ||
| 192 | </td>  | 
            ||
| 193 | <td class='$class' align='center'>  | 
            ||
| 194 | <input type='text' name=weight[$bid] value='$weight' size='5' maxlength='5' style='text-align:right;'>  | 
            ||
| 195 | </td>  | 
            ||
| 196 | <td class='$class' align='center'>  | 
            ||
| 197 | <select name='bmodule[$bid][]' size='5' multiple='multiple'>  | 
            ||
| 198 | $module_options  | 
            ||
| 199 | </select>  | 
            ||
| 200 | </td>  | 
            ||
| 201 | <td class='$class' align='center'>  | 
            ||
| 202 | <select name='bcachetime[$bid]' size='1'>  | 
            ||
| 203 | $cachetime_options  | 
            ||
| 204 | </select>  | 
            ||
| 205 | </td>  | 
            ||
| 206 | <td class='$class' align='center'>  | 
            ||
| 207 | <a href='admin.php?fct=blocksadmin&op=edit&bid=$bid'>"  | 
            ||
| 208 | . _EDIT  | 
            ||
| 209 | . "</a>  | 
            ||
| 210 | <input type='hidden' name='bid[$bid]' value='$bid'>  | 
            ||
| 211 | </td>  | 
            ||
| 212 | </tr>\n";  | 
            ||
| 213 | |||
| 214 |         $class = ('even' === $class) ? 'odd' : 'even'; | 
            ||
| 215 | }  | 
            ||
| 216 | |||
| 217 | echo "  | 
            ||
| 218 | <tr>  | 
            ||
| 219 | <td class='foot' align='center' colspan='6'>  | 
            ||
| 220 | <input type='hidden' name='fct' value='blocksadmin'>  | 
            ||
| 221 | <input type='hidden' name='op' value='order'>  | 
            ||
| 222 | <input type='submit' name='submit' value='" . _SUBMIT . "'>  | 
            ||
| 223 | </td>  | 
            ||
| 224 | </tr>  | 
            ||
| 225 | </table>  | 
            ||
| 226 | </form>\n";  | 
            ||
| 227 | echo '</div>';  | 
            ||
| 228 | }  | 
            ||
| 229 | |||
| 273 |