| Conditions | 28 | 
| Paths | 2881 | 
| Total Lines | 222 | 
| Code Lines | 150 | 
| 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 | ||
| 74 | } | ||
| 75 | |||
| 76 | function list_blocks() | ||
| 77 | { | ||
| 78 | global $query4redirect, $block_arr; | ||
| 79 | // cachetime options | ||
| 80 | $cachetimes = [ | ||
| 81 | '0' => _NOCACHE, | ||
| 82 | '30' => sprintf(_SECONDS, 30), | ||
| 83 | '60' => _MINUTE, | ||
| 84 | '300' => sprintf(_MINUTES, 5), | ||
| 85 | '1800' => sprintf(_MINUTES, 30), | ||
| 86 | '3600' => _HOUR, | ||
| 87 | '18000' => sprintf(_HOURS, 5), | ||
| 88 | '86400' => _DAY, | ||
| 89 | '259200' => sprintf(_DAYS, 3), | ||
| 90 | '604800' => _WEEK, | ||
| 91 | '2592000' => _MONTH, | ||
| 92 | ]; | ||
| 93 | // displaying TH | ||
| 94 | echo " | ||
| 95 | <form action='admin.php' name='blockadmin' method='post'> | ||
| 96 | <table width='95%' class='outer' cellpadding='4' cellspacing='1'> | ||
| 97 | <tr valign='middle'> | ||
| 98 | <th style='text-align: left;'>" . _AM_TITLE . "</th> | ||
| 99 | <th class='center;' nowrap='nowrap'>" . _AM_SIDE . "</th> | ||
| 100 | <th class='center;'>" . _AM_WEIGHT . "</th> | ||
| 101 | <th class='center;'>" . _AM_VISIBLEIN . "</th> | ||
| 102 | <th class='center;'>" . _AM_BCACHETIME . "</th> | ||
| 103 | <th class='center;'>" . _AM_ACTION . "</th> | ||
| 104 | </tr>\n"; | ||
| 105 | // blocks displaying loop | ||
| 106 | $class = 'even'; | ||
| 107 | $block_configs = get_block_configs(); | ||
| 108 |     foreach (array_keys($block_arr) as $i) { | ||
| 109 | $sseln = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = ''; | ||
| 110 | $scoln = $scol0 = $scol1 = $scol2 = $scol3 = $scol4 = $scol5 = $scol6 = $scol7 = '#FFFFFF'; | ||
| 111 | |||
| 112 |         $weight     = $block_arr[$i]->getVar('weight'); | ||
| 113 |         $title      = $block_arr[$i]->getVar('title'); | ||
| 114 |         $name       = $block_arr[$i]->getVar('name'); | ||
| 115 |         $bcachetime = $block_arr[$i]->getVar('bcachetime'); | ||
| 116 | |||
| 117 |         $bid = $block_arr[$i]->getVar('bid'); | ||
| 118 | // visible and side | ||
| 119 |         if (1 != $block_arr[$i]->getVar('visible')) { | ||
| 120 | $sseln = ' checked'; | ||
| 121 | $scoln = '#FF0000'; | ||
| 122 |         } else { | ||
| 123 |             switch ($block_arr[$i]->getVar('side')) { | ||
| 124 | default: | ||
| 125 | case XOOPS_SIDEBLOCK_LEFT: | ||
| 126 | $ssel0 = ' checked'; | ||
| 127 | $scol0 = '#00FF00'; | ||
| 128 | break; | ||
| 129 | case XOOPS_SIDEBLOCK_RIGHT: | ||
| 130 | $ssel1 = ' checked'; | ||
| 131 | $scol1 = '#00FF00'; | ||
| 132 | break; | ||
| 133 | case XOOPS_CENTERBLOCK_LEFT: | ||
| 134 | $ssel2 = ' checked'; | ||
| 135 | $scol2 = '#00FF00'; | ||
| 136 | break; | ||
| 137 | case XOOPS_CENTERBLOCK_RIGHT: | ||
| 138 | $ssel4 = ' checked'; | ||
| 139 | $scol4 = '#00FF00'; | ||
| 140 | break; | ||
| 141 | case XOOPS_CENTERBLOCK_CENTER: | ||
| 142 | $ssel3 = ' checked'; | ||
| 143 | $scol3 = '#00FF00'; | ||
| 144 | break; | ||
| 145 | case XOOPS_CENTERBLOCK_BOTTOMLEFT: | ||
| 146 | $ssel5 = ' checked'; | ||
| 147 | $scol5 = '#00FF00'; | ||
| 148 | break; | ||
| 149 | case XOOPS_CENTERBLOCK_BOTTOMRIGHT: | ||
| 150 | $ssel7 = ' checked'; | ||
| 151 | $scol7 = '#00FF00'; | ||
| 152 | break; | ||
| 153 | case XOOPS_CENTERBLOCK_BOTTOM: | ||
| 154 | $ssel6 = ' checked'; | ||
| 155 | $scol6 = '#00FF00'; | ||
| 156 | break; | ||
| 157 | } | ||
| 158 | } | ||
| 159 | // bcachetime | ||
| 160 | $cachetime_options = ''; | ||
| 161 |         foreach ($cachetimes as $cachetime => $cachetime_name) { | ||
| 162 |             if ($bcachetime == $cachetime) { | ||
| 163 | $cachetime_options .= "<option value='$cachetime' selected>$cachetime_name</option>\n"; | ||
| 164 |             } else { | ||
| 165 | $cachetime_options .= "<option value='$cachetime'>$cachetime_name</option>\n"; | ||
| 166 | } | ||
| 167 | } | ||
| 168 | // target modules | ||
| 169 | $db = \XoopsDatabaseFactory:: getDatabaseConnection(); | ||
| 170 |         $result        = $db->query('SELECT module_id FROM ' . $db->prefix('block_module_link') . " WHERE block_id='$bid'"); | ||
| 171 | $selected_mids = []; | ||
| 172 |         while (list($selected_mid) = $db->fetchRow($result)) { | ||
| 173 | $selected_mids[] = (int)$selected_mid; | ||
| 174 | } | ||
| 175 | /** @var \XoopsModuleHandler $moduleHandler */ | ||
| 176 |         $moduleHandler = xoops_getHandler('module'); | ||
| 177 |         $criteria      = new \CriteriaCompo(new \Criteria('hasmain', 1)); | ||
| 178 |         $criteria->add(new \Criteria('isactive', 1)); | ||
| 179 | $module_list = $moduleHandler->getList($criteria); | ||
| 180 | $module_list[-1] = _AM_TOPPAGE; | ||
| 181 | $module_list[0] = _AM_ALLPAGES; | ||
| 182 | ksort($module_list); | ||
| 183 | $module_options = ''; | ||
| 184 |         foreach ($module_list as $mid => $mname) { | ||
| 185 |             if (in_array($mid, $selected_mids)) { | ||
| 186 | $module_options .= "<option value='$mid' selected>$mname</option>\n"; | ||
| 187 |             } else { | ||
| 188 | $module_options .= "<option value='$mid'>$mname</option>\n"; | ||
| 189 | } | ||
| 190 | } | ||
| 191 | // delete link if it is cloned block | ||
| 192 | $delete_link = ''; | ||
| 193 |         if ('D' === $block_arr[$i]->getVar('block_type') || 'C' === $block_arr[$i]->getVar('block_type')) { | ||
| 194 | $delete_link = "<br><a href='admin.php?fct=blocksadmin&op=delete&bid=$bid'>" . _DELETE . '</a>'; | ||
| 195 | } | ||
| 196 | // clone link if it is marked as cloneable block | ||
| 197 | // $modversion['blocks'][n]['can_clone'] | ||
| 198 |         if ('D' === $block_arr[$i]->getVar('block_type') || 'C' === $block_arr[$i]->getVar('block_type')) { | ||
| 199 | $can_clone = true; | ||
| 200 |         } else { | ||
| 201 | $can_clone = false; | ||
| 202 |             foreach ($block_configs as $bconf) { | ||
| 203 |                 if ($block_arr[$i]->getVar('show_func') == $bconf['show_func'] | ||
| 204 |                     && $block_arr[$i]->getVar('func_file') == $bconf['file'] | ||
| 205 | && (empty($bconf['template']) | ||
| 206 |                         || $block_arr[$i]->getVar('template') == $bconf['template'])) { | ||
| 207 |                     if (!empty($bconf['can_clone'])) { | ||
| 208 | $can_clone = true; | ||
| 209 | } | ||
| 210 | } | ||
| 211 | } | ||
| 212 | } | ||
| 213 | $clone_link = ''; | ||
| 214 |         if ($can_clone) { | ||
| 215 | $clone_link = "<br><a href='admin.php?fct=blocksadmin&op=clone&bid=$bid'>" . _CLONE . '</a>'; | ||
| 216 | } | ||
| 217 | // displaying part | ||
| 218 | echo " | ||
| 219 | <tr valign='middle'> | ||
| 220 | <td class='$class'> | ||
| 221 | $name | ||
| 222 | <br> | ||
| 223 | <input type='text' name='title[$bid]' value='$title' size='20'> | ||
| 224 | </td> | ||
| 225 | <td class='$class' class='center;' nowrap='nowrap' width='110px'> | ||
| 226 | <div style='float:left;background-color:$scol0;'> | ||
| 227 | <input type='radio' name='side[$bid]' value='" . XOOPS_SIDEBLOCK_LEFT . "' style='background-color:$scol0;' $ssel0> | ||
| 228 | </div> | ||
| 229 | <div style='float:left;'>-</div> | ||
| 230 | <div style='float:left;background-color:$scol2;'> | ||
| 231 | <input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_LEFT . "' style='background-color:$scol2;' $ssel2> | ||
| 232 | </div> | ||
| 233 | <div style='float:left;background-color:$scol3;'> | ||
| 234 | <input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_CENTER . "' style='background-color:$scol3;' $ssel3> | ||
| 235 | </div> | ||
| 236 | <div style='float:left;background-color:$scol4;'> | ||
| 237 | <input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_RIGHT . "' style='background-color:$scol4;' $ssel4> | ||
| 238 | </div> | ||
| 239 | <div style='float:left;'>-</div> | ||
| 240 | <div style='float:left;background-color:$scol1;'> | ||
| 241 | <input type='radio' name='side[$bid]' value='" . XOOPS_SIDEBLOCK_RIGHT . "' style='background-color:$scol1;' $ssel1> | ||
| 242 | </div> | ||
| 243 | <br> | ||
| 244 | <div style='float:left;width:25px;'> </div> | ||
| 245 | <div style='float:left;background-color:$scol5;'> | ||
| 246 | <input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_BOTTOMLEFT . "' style='background-color:$scol5;' $ssel5> | ||
| 247 | </div> | ||
| 248 | <div style='float:left;background-color:$scol6;'> | ||
| 249 | <input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_BOTTOM . "' style='background-color:$scol6;' $ssel6> | ||
| 250 | </div> | ||
| 251 | <div style='float:left;background-color:$scol7;'> | ||
| 252 | <input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_BOTTOMRIGHT . "' style='background-color:$scol7;' $ssel7> | ||
| 253 | </div> | ||
| 254 | <div style='float:left;width:25px;'> </div> | ||
| 255 | <br> | ||
| 256 | <br> | ||
| 257 | <div style='float:left;width:40px;'> </div> | ||
| 258 | <div style='float:left;background-color:$scoln;'> | ||
| 259 | <input type='radio' name='side[$bid]' value='-1' style='background-color:$scoln;' $sseln> | ||
| 260 | </div> | ||
| 261 | <div style='float:left;'>" . _NONE . "</div> | ||
| 262 | </td> | ||
| 263 | <td class='$class' class='center;'> | ||
| 264 | <input type='text' name=weight[$bid] value='$weight' size='3' maxlength='5' style='text-align:right;'> | ||
| 265 | </td> | ||
| 266 | <td class='$class' class='center;'> | ||
| 267 | <select name='bmodule[$bid][]' size='5' multiple='multiple'> | ||
| 268 | $module_options | ||
| 269 | </select> | ||
| 270 | </td> | ||
| 271 | <td class='$class' class='center;'> | ||
| 272 | <select name='bcachetime[$bid]' size='1'> | ||
| 273 | $cachetime_options | ||
| 274 | </select> | ||
| 275 | </td> | ||
| 276 | <td class='$class' class='center;'> | ||
| 277 |                 <a href='admin.php?fct=blocksadmin&op=edit&bid=$bid'>" . _EDIT . "</a>{$delete_link}{$clone_link} | ||
| 278 | <input type='hidden' name='bid[$bid]' value='$bid'> | ||
| 279 | </td> | ||
| 280 | </tr>\n"; | ||
| 281 | |||
| 282 |         $class = ('even' === $class) ? 'odd' : 'even'; | ||
| 283 | } | ||
| 284 | |||
| 285 | echo " | ||
| 286 | <tr> | ||
| 287 | <td class='foot' class='center;' colspan='6'> | ||
| 288 | <input type='hidden' name='query4redirect' value='$query4redirect'> | ||
| 289 | <input type='hidden' name='fct' value='blocksadmin'> | ||
| 290 | <input type='hidden' name='op' value='order'> | ||
| 291 | " . $GLOBALS['xoopsSecurity']->getTokenHTML() . " | ||
| 292 | <input type='submit' name='submit' value='" . _SUBMIT . "'> | ||
| 293 | </td> | ||
| 294 | </tr> | ||
| 295 | </table> | ||
| 296 | </form>\n"; | ||
| 358 |