| Conditions | 21 |
| Paths | 1728 |
| Total Lines | 111 |
| 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 |
||
| 68 | public function getSearchForm($plugin, $action_after_read = 1, $limitcheck = 0, $action = false) |
||
| 69 | { |
||
| 70 | global $xoopsDB; |
||
| 71 | |||
| 72 | if (false === $action) { |
||
| 73 | $action = $_SERVER['REQUEST_URI']; |
||
| 74 | } |
||
| 75 | |||
| 76 | $title = _AM_XNEWSLETTER_IMPORT_SEARCH; |
||
| 77 | |||
| 78 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 79 | $form = new \XoopsThemeForm($title, 'form_select_import', $action, 'post', true); |
||
| 80 | $form->setExtra('enctype="multipart/form-data"'); |
||
| 81 | |||
| 82 | $catCriteria = new \CriteriaCompo(); |
||
| 83 | $catCriteria->setSort('cat_id ASC, cat_name'); |
||
| 84 | $catCriteria->setOrder('ASC'); |
||
| 85 | $cat_select = new \XoopsFormSelect(_AM_XNEWSLETTER_IMPORT_PRESELECT_CAT, 'cat_id', '1'); |
||
| 86 | $cat_select->addOptionArray($this->helper->getHandler('Cat')->getList($catCriteria)); |
||
| 87 | $form->addElement($cat_select, false); |
||
| 88 | |||
| 89 | $opt_import_type = new \XoopsFormRadio(_AM_XNEWSLETTER_IMPORT_PLUGINS_AVAIL, 'plugin', $plugin, '<br>'); |
||
| 90 | $opt_import_type->setExtra('onclick="document.forms.form_select_import.submit()"'); |
||
| 91 | $aFiles = \XoopsLists::getFileListAsArray(XNEWSLETTER_ROOT_PATH . '/plugins/'); |
||
| 92 | $arrPlugin = []; |
||
|
|
|||
| 93 | $currpluginhasform = 0; |
||
| 94 | foreach ($aFiles as $file) { |
||
| 95 | if ('.php' === mb_substr($file, mb_strlen($file) - 4, 4)) { |
||
| 96 | $pluginName = str_replace('.php', '', $file); |
||
| 97 | $pluginFile = XNEWSLETTER_ROOT_PATH . '/plugins/' . $pluginName . '.php'; |
||
| 98 | if (file_exists($pluginFile)) { |
||
| 99 | require_once $pluginFile; |
||
| 100 | $function = 'xnewsletter_plugin_getinfo_' . $pluginName; |
||
| 101 | $arrPlugin = $function(); |
||
| 102 | $show_plugin = $this->tableExists($arrPlugin['tables'][0]); |
||
| 103 | if (true === $show_plugin && @is_array($arrPlugin['tables'][1])) { |
||
| 104 | $show_plugin = $this->tableExists($arrPlugin['tables'][1]); |
||
| 105 | } |
||
| 106 | |||
| 107 | if (true === $show_plugin) { |
||
| 108 | $label = "<img src='" . $arrPlugin['icon'] . "' title='" . $arrPlugin['descr'] . "' alt='" . $arrPlugin['descr'] . "' style='height:32px;margin-bottom:5px;margin-right:5px'>" . $arrPlugin['descr']; |
||
| 109 | $opt_import_type->addOption($arrPlugin['name'], $label); |
||
| 110 | $form->addElement(new \XoopsFormHidden('hasform_' . $pluginName, $arrPlugin['hasform'])); |
||
| 111 | if ($plugin == $pluginName && 1 == $arrPlugin['hasform']) { |
||
| 112 | $currpluginhasform = 1; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | } |
||
| 116 | } |
||
| 117 | } |
||
| 118 | $form->addElement($opt_import_type, false); |
||
| 119 | |||
| 120 | //option, whether data should be shown for check or directly imported |
||
| 121 | $check_after = new \XoopsFormRadio(_AM_XNEWSLETTER_IMPORT_AFTER_READ, 'action_after_read', $action_after_read, '<br>'); |
||
| 122 | $check_after->addOption(0, _AM_XNEWSLETTER_IMPORT_READ_IMPORT); |
||
| 123 | $check_after->addOption(1, _AM_XNEWSLETTER_IMPORT_READ_CHECK); |
||
| 124 | $check_after->setExtra('onclick="document.forms.form_select_import.submit()"'); |
||
| 125 | $form->addElement($check_after, false); |
||
| 126 | |||
| 127 | //limit for import |
||
| 128 | $form->addElement(new \XoopsFormLabel(_AM_XNEWSLETTER_IMPORT_CHECK_LIMIT, '100000'), false); |
||
| 129 | if (0 == $action_after_read) { |
||
| 130 | if ($limitcheck < 500 && $limitcheck > 0) { |
||
| 131 | $limitcheck = 500; |
||
| 132 | } |
||
| 133 | } else { |
||
| 134 | if ($limitcheck > 200) { |
||
| 135 | $limitcheck = 200; |
||
| 136 | } |
||
| 137 | } |
||
| 138 | $sel_limitcheck = new \XoopsFormSelect(_AM_XNEWSLETTER_IMPORT_CHECK_LIMIT_PACKAGE, 'limitcheck', $limitcheck); |
||
| 139 | if (0 == $action_after_read) { |
||
| 140 | $sel_limitcheck->addOption(0, _AM_XNEWSLETTER_IMPORT_NOLIMIT); |
||
| 141 | $sel_limitcheck->addOption(500, 500); |
||
| 142 | $sel_limitcheck->addOption(1000, 1000); |
||
| 143 | $sel_limitcheck->addOption(10000, 10000); |
||
| 144 | $sel_limitcheck->addOption(25000, 25000); |
||
| 145 | } else { |
||
| 146 | $limitOptions = [25, 50, 100, 200, 400]; |
||
| 147 | foreach ($limitOptions as $limitOption) { |
||
| 148 | // check if limit options are compatible with php.ini 'max_input_vars' setting |
||
| 149 | if ((0 == ini_get('max_input_vars')) || ((($limitOption * 7) + 4) < ini_get('max_input_vars'))) { |
||
| 150 | $sel_limitcheck->addOption($limitOption, $limitOption); |
||
| 151 | } |
||
| 152 | } |
||
| 153 | } |
||
| 154 | $form->addElement($sel_limitcheck, false); |
||
| 155 | |||
| 156 | $skip = 1 == $action_after_read ? 0 : 1; |
||
| 157 | $skipcatsubscrexist = new \XoopsFormRadioYN(_AM_XNEWSLETTER_IMPORT_SKIP_EXISTING, 'skipcatsubscrexist', $skip); |
||
| 158 | if (0 == $action_after_read) { |
||
| 159 | $skipcatsubscrexist->setExtra('disabled="disabled"'); |
||
| 160 | } |
||
| 161 | $form->addElement($skipcatsubscrexist, false); |
||
| 162 | |||
| 163 | $form->addElement(new \XoopsFormHidden('op', 'default')); |
||
| 164 | $buttonTray = new \XoopsFormElementTray('', ''); |
||
| 165 | if (1 == $currpluginhasform) { |
||
| 166 | //show form for additional options |
||
| 167 | $button1 = new \XoopsFormButton('', 'form_additional', _AM_XNEWSLETTER_IMPORT_CONTINUE, 'submit1'); |
||
| 168 | $button1->setExtra('onclick="document.getElementById(\'op\').value = \'form_additional\';document.forms.form_select_import.submit()"'); |
||
| 169 | $buttonTray->addElement($button1); |
||
| 170 | } else { |
||
| 171 | $button2 = new \XoopsFormButton('', 'searchdata', _AM_XNEWSLETTER_IMPORT_CONTINUE, 'submit2'); |
||
| 172 | $button2->setExtra('onclick="document.getElementById(\'op\').value = \'searchdata\';document.forms.form_select_import.submit()"'); |
||
| 173 | $buttonTray->addElement($button2); |
||
| 174 | } |
||
| 175 | $form->addElement($buttonTray); |
||
| 176 | |||
| 177 | return $form; |
||
| 178 | } |
||
| 179 | |||
| 196 |
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.