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