| Conditions | 22 | 
| Paths | 3457 | 
| Total Lines | 229 | 
| Lines | 3 | 
| Ratio | 1.31 % | 
| 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  | 
            ||
| 49 | function listBlocks()  | 
            ||
| 50 |     { | 
            ||
| 51 | global $xoopsModule, $pathIcon16;  | 
            ||
| 52 | require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';  | 
            ||
| 53 | $moduleDirName = basename(dirname(__DIR__));  | 
            ||
| 54 | $moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName  | 
            ||
| 55 | $db = \XoopsDatabaseFactory::getDatabaseConnection();  | 
            ||
| 56 |         xoops_loadLanguage('admin', 'system'); | 
            ||
| 57 |         xoops_loadLanguage('admin/blocksadmin', 'system'); | 
            ||
| 58 |         xoops_loadLanguage('admin/groups', 'system'); | 
            ||
| 59 | |||
| 60 | /** @var \XoopsModuleHandler $moduleHandler */  | 
            ||
| 61 |         $moduleHandler = xoops_getHandler('module'); | 
            ||
| 62 | /** @var \XoopsMemberHandler $memberHandler */  | 
            ||
| 63 |         $memberHandler = xoops_getHandler('member'); | 
            ||
| 64 | /** @var \XoopsGroupPermHandler $grouppermHandler */  | 
            ||
| 65 |         $grouppermHandler = xoops_getHandler('groupperm'); | 
            ||
| 66 | $groups = $memberHandler->getGroups();  | 
            ||
| 67 |         $criteria         = new \CriteriaCompo(new \Criteria('hasmain', 1)); | 
            ||
| 68 |         $criteria->add(new \Criteria('isactive', 1)); | 
            ||
| 69 | $module_list = $moduleHandler->getList($criteria);  | 
            ||
| 70 | $module_list[-1] = _AM_SYSTEM_BLOCKS_TOPPAGE;  | 
            ||
| 71 | $module_list[0] = _AM_SYSTEM_BLOCKS_ALLPAGES;  | 
            ||
| 72 | ksort($module_list);  | 
            ||
| 73 | echo "  | 
            ||
| 74 |         <h4 style='text-align:left;'>" . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</h4>'; | 
            ||
| 75 |         $moduleHandler = xoops_getHandler('module'); | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 76 | echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>";  | 
            ||
| 77 | echo $GLOBALS['xoopsSecurity']->getTokenHTML();  | 
            ||
| 78 | echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'>  | 
            ||
| 79 | <tr valign='middle'><th align='center'>"  | 
            ||
| 80 |              . constant('CO_' . $moduleDirNameUpper . '_' . 'TITLE') | 
            ||
| 81 | . "</th><th align='center' nowrap='nowrap'>"  | 
            ||
| 82 |              . constant('CO_' . $moduleDirNameUpper . '_' . 'SIDE') | 
            ||
| 83 | . '<br>'  | 
            ||
| 84 | . _LEFT  | 
            ||
| 85 | . '-'  | 
            ||
| 86 | . _CENTER  | 
            ||
| 87 | . '-'  | 
            ||
| 88 | . _RIGHT  | 
            ||
| 89 | . "</th><th align='center'>"  | 
            ||
| 90 | . constant(  | 
            ||
| 91 | 'CO_' . $moduleDirNameUpper . '_' . 'WEIGHT'  | 
            ||
| 92 | )  | 
            ||
| 93 | . "</th><th align='center'>"  | 
            ||
| 94 |              . constant('CO_' . $moduleDirNameUpper . '_' . 'VISIBLE') | 
            ||
| 95 | . "</th><th align='center'>"  | 
            ||
| 96 | . _AM_SYSTEM_BLOCKS_VISIBLEIN  | 
            ||
| 97 | . "</th><th align='center'>"  | 
            ||
| 98 | . _AM_SYSTEM_ADGS  | 
            ||
| 99 | . "</th><th align='center'>"  | 
            ||
| 100 | . _AM_SYSTEM_BLOCKS_BCACHETIME  | 
            ||
| 101 | . "</th><th align='center'>"  | 
            ||
| 102 |              . constant('CO_' . $moduleDirNameUpper . '_' . 'ACTION') | 
            ||
| 103 | . '</th></tr>  | 
            ||
| 104 | ';  | 
            ||
| 105 | $block_arr = \XoopsBlock::getByModule($xoopsModule->mid());  | 
            ||
| 106 | $block_count = count($block_arr);  | 
            ||
| 107 | $class = 'even';  | 
            ||
| 108 | $cachetimes = [  | 
            ||
| 109 | '0' => _NOCACHE,  | 
            ||
| 110 | '30' => sprintf(_SECONDS, 30),  | 
            ||
| 111 | '60' => _MINUTE,  | 
            ||
| 112 | '300' => sprintf(_MINUTES, 5),  | 
            ||
| 113 | '1800' => sprintf(_MINUTES, 30),  | 
            ||
| 114 | '3600' => _HOUR,  | 
            ||
| 115 | '18000' => sprintf(_HOURS, 5),  | 
            ||
| 116 | '86400' => _DAY,  | 
            ||
| 117 | '259200' => sprintf(_DAYS, 3),  | 
            ||
| 118 | '604800' => _WEEK,  | 
            ||
| 119 | '2592000' => _MONTH,  | 
            ||
| 120 | ];  | 
            ||
| 121 |         foreach ($block_arr as $i) { | 
            ||
| 122 |             $groups_perms = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid')); | 
            ||
| 123 |             $sql          = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid'); | 
            ||
| 124 | $result = $db->query($sql);  | 
            ||
| 125 | $modules = [];  | 
            ||
| 126 | View Code Duplication |             while (false !== ($row = $db->fetchArray($result))) { | 
            |
| 127 | $modules[] = (int)$row['module_id'];  | 
            ||
| 128 | }  | 
            ||
| 129 | |||
| 130 | $cachetime_options = '';  | 
            ||
| 131 |             foreach ($cachetimes as $cachetime => $cachetime_name) { | 
            ||
| 132 |                 if ($i->getVar('bcachetime') == $cachetime) { | 
            ||
| 133 | $cachetime_options .= "<option value='$cachetime' selected>$cachetime_name</option>\n";  | 
            ||
| 134 |                 } else { | 
            ||
| 135 | $cachetime_options .= "<option value='$cachetime'>$cachetime_name</option>\n";  | 
            ||
| 136 | }  | 
            ||
| 137 | }  | 
            ||
| 138 | |||
| 139 | $sel0 = $sel1 = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = '';  | 
            ||
| 140 |             if (1 === $i->getVar('visible')) { | 
            ||
| 141 | $sel1 = ' checked';  | 
            ||
| 142 |             } else { | 
            ||
| 143 | $sel0 = ' checked';  | 
            ||
| 144 | }  | 
            ||
| 145 |             if (XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) { | 
            ||
| 146 | $ssel0 = ' checked';  | 
            ||
| 147 |             } elseif (XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) { | 
            ||
| 148 | $ssel1 = ' checked';  | 
            ||
| 149 |             } elseif (XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) { | 
            ||
| 150 | $ssel2 = ' checked';  | 
            ||
| 151 |             } elseif (XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) { | 
            ||
| 152 | $ssel4 = ' checked';  | 
            ||
| 153 |             } elseif (XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) { | 
            ||
| 154 | $ssel3 = ' checked';  | 
            ||
| 155 |             } elseif (XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) { | 
            ||
| 156 | $ssel5 = ' checked';  | 
            ||
| 157 |             } elseif (XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) { | 
            ||
| 158 | $ssel6 = ' checked';  | 
            ||
| 159 |             } elseif (XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) { | 
            ||
| 160 | $ssel7 = ' checked';  | 
            ||
| 161 | }  | 
            ||
| 162 |             if ('' === $i->getVar('title')) { | 
            ||
| 163 | $title = ' ';  | 
            ||
| 164 |             } else { | 
            ||
| 165 |                 $title = $i->getVar('title'); | 
            ||
| 166 | }  | 
            ||
| 167 |             $name = $i->getVar('name'); | 
            ||
| 168 | echo "<tr valign='top'><td class='$class' align='center'><input type='text' name='title["  | 
            ||
| 169 |                  . $i->getVar('bid') | 
            ||
| 170 | . "]' value='"  | 
            ||
| 171 | . $title  | 
            ||
| 172 | . "'></td><td class='$class' align='center' nowrap='nowrap'>  | 
            ||
| 173 | <div align='center' >  | 
            ||
| 174 | <input type='radio' name='side["  | 
            ||
| 175 |                  . $i->getVar('bid') | 
            ||
| 176 | . "]' value='"  | 
            ||
| 177 | . XOOPS_CENTERBLOCK_LEFT  | 
            ||
| 178 | . "'$ssel2>  | 
            ||
| 179 | <input type='radio' name='side["  | 
            ||
| 180 |                  . $i->getVar('bid') | 
            ||
| 181 | . "]' value='"  | 
            ||
| 182 | . XOOPS_CENTERBLOCK_CENTER  | 
            ||
| 183 | . "'$ssel3>  | 
            ||
| 184 | <input type='radio' name='side["  | 
            ||
| 185 |                  . $i->getVar('bid') | 
            ||
| 186 | . "]' value='"  | 
            ||
| 187 | . XOOPS_CENTERBLOCK_RIGHT  | 
            ||
| 188 | . "'$ssel4>  | 
            ||
| 189 | </div>  | 
            ||
| 190 | <div>  | 
            ||
| 191 | <span style='float:right;'><input type='radio' name='side["  | 
            ||
| 192 |                  . $i->getVar('bid') | 
            ||
| 193 | . "]' value='"  | 
            ||
| 194 | . XOOPS_SIDEBLOCK_RIGHT  | 
            ||
| 195 | . "'$ssel1></span>  | 
            ||
| 196 | <div align='left'><input type='radio' name='side["  | 
            ||
| 197 |                  . $i->getVar('bid') | 
            ||
| 198 | . "]' value='"  | 
            ||
| 199 | . XOOPS_SIDEBLOCK_LEFT  | 
            ||
| 200 | . "'$ssel0></div>  | 
            ||
| 201 | </div>  | 
            ||
| 202 | <div align='center'>  | 
            ||
| 203 | <input type='radio' name='side["  | 
            ||
| 204 |                  . $i->getVar('bid') | 
            ||
| 205 | . "]' value='"  | 
            ||
| 206 | . XOOPS_CENTERBLOCK_BOTTOMLEFT  | 
            ||
| 207 | . "'$ssel5>  | 
            ||
| 208 | <input type='radio' name='side["  | 
            ||
| 209 |                  . $i->getVar('bid') | 
            ||
| 210 | . "]' value='"  | 
            ||
| 211 | . XOOPS_CENTERBLOCK_BOTTOM  | 
            ||
| 212 | . "'$ssel7>  | 
            ||
| 213 | <input type='radio' name='side["  | 
            ||
| 214 |                  . $i->getVar('bid') | 
            ||
| 215 | . "]' value='"  | 
            ||
| 216 | . XOOPS_CENTERBLOCK_BOTTOMRIGHT  | 
            ||
| 217 | . "'$ssel6>  | 
            ||
| 218 | </div>  | 
            ||
| 219 | </td><td class='$class' align='center'><input type='text' name='weight["  | 
            ||
| 220 |                  . $i->getVar('bid') | 
            ||
| 221 | . "]' value='"  | 
            ||
| 222 |                  . $i->getVar('weight') | 
            ||
| 223 | . "' size='5' maxlength='5'></td><td class='$class' align='center' nowrap><input type='radio' name='visible["  | 
            ||
| 224 |                  . $i->getVar('bid') | 
            ||
| 225 | . "]' value='1'$sel1>"  | 
            ||
| 226 | . _YES  | 
            ||
| 227 | . " <input type='radio' name='visible["  | 
            ||
| 228 |                  . $i->getVar('bid') | 
            ||
| 229 | . "]' value='0'$sel0>"  | 
            ||
| 230 | . _NO  | 
            ||
| 231 | . '</td>';  | 
            ||
| 232 | |||
| 233 |             echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>"; | 
            ||
| 234 |             foreach ($module_list as $k => $v) { | 
            ||
| 235 | echo "<option value='$k'" . (in_array($k, $modules) ? 'selected' : '') . ">$v</option>";  | 
            ||
| 236 | }  | 
            ||
| 237 | echo '</select></td>';  | 
            ||
| 238 | |||
| 239 |             echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>"; | 
            ||
| 240 |             foreach ($groups as $grp) { | 
            ||
| 241 |                 echo "<option value='" . $grp->getVar('groupid') . "' " . (in_array($grp->getVar('groupid'), $groups_perms) ? 'selected' : '') . '>' . $grp->getVar('name') . '</option>'; | 
            ||
| 242 | }  | 
            ||
| 243 | echo '</select></td>';  | 
            ||
| 244 | |||
| 245 | // Cache lifetime  | 
            ||
| 246 |             echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetime_options . '</select> | 
            ||
| 247 | </td>';  | 
            ||
| 248 | |||
| 249 | // Actions  | 
            ||
| 250 | |||
| 251 |             echo "<td class='$class' align='center'><a href='blocksadmin.php?op=edit&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/edit.png' . " alt='" . _EDIT . "' title='" . _EDIT . "'> | 
            ||
| 252 |                  </a> <a href='blocksadmin.php?op=clone&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'> | 
            ||
| 253 | </a>";  | 
            ||
| 254 |             if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) { | 
            ||
| 255 |                 echo " <a href='" . XOOPS_URL . '/modules/system/admin.php?fct=blocksadmin&op=delete&bid=' . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'> | 
            ||
| 256 | </a>";  | 
            ||
| 257 | }  | 
            ||
| 258 | echo "  | 
            ||
| 259 |             <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'> | 
            ||
| 260 |             <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'> | 
            ||
| 261 |             <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'> | 
            ||
| 262 |             <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'> | 
            ||
| 263 |             <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'> | 
            ||
| 264 |             <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'> | 
            ||
| 265 |             <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'> | 
            ||
| 266 | </td></tr>  | 
            ||
| 267 | ";  | 
            ||
| 268 |             $class = ('even' === $class) ? 'odd' : 'even'; | 
            ||
| 269 | }  | 
            ||
| 270 | echo "<tr><td class='foot' align='center' colspan='8'>  | 
            ||
| 271 | <input type='hidden' name='op' value='order'>  | 
            ||
| 272 | " . $GLOBALS['xoopsSecurity']->getTokenHTML() . "  | 
            ||
| 273 | <input type='submit' name='submit' value='" . _SUBMIT . "'>  | 
            ||
| 274 | </td></tr></table>  | 
            ||
| 275 | </form>  | 
            ||
| 276 | <br><br>";  | 
            ||
| 277 | }  | 
            ||
| 278 | |||
| 576 | 
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.