Conditions | 3 |
Paths | 2 |
Total Lines | 74 |
Code Lines | 61 |
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 declare(strict_types=1); |
||
192 | function publisher_items_spot_edit($options) |
||
193 | { |
||
194 | // require_once PUBLISHER_ROOT_PATH . '/class/blockform.php'; |
||
195 | xoops_load('XoopsFormLoader'); |
||
196 | $form = new BlockForm(); |
||
197 | $autoEle = new \XoopsFormRadioYN(_MB_PUBLISHER_AUTO_LAST_ITEMS, 'options[0]', $options[0]); |
||
198 | $countEle = new \XoopsFormText(_MB_PUBLISHER_LAST_ITEMS_COUNT, 'options[1]', 2, 255, $options[1]); |
||
199 | $catEle = new \XoopsFormLabel(_MB_PUBLISHER_SELECTCAT, Utility::createCategorySelect($options[2], 0, true, 'options[2]', false)); |
||
200 | $helper = Helper::getInstance(); |
||
201 | /** @var ItemHandler $itemHandler */ |
||
202 | $itemHandler = $helper->getHandler('Item'); |
||
203 | $criteria = new \CriteriaCompo(); |
||
204 | $criteria->setSort('datesub'); |
||
205 | $criteria->setOrder('DESC'); |
||
206 | $itemsObj = $itemHandler->getList($criteria); |
||
207 | $keys = array_keys($itemsObj); |
||
208 | unset($criteria); |
||
209 | if (empty($options[3]) || (0 == $options[3])) { |
||
210 | $selItems = $keys[0] ?? 0; |
||
211 | } else { |
||
212 | $selItems = explode(',', $options[3]); |
||
213 | } |
||
214 | $itemEle = new \XoopsFormSelect(_MB_PUBLISHER_SELECT_ITEMS, 'options[3]', $selItems, 10, true); |
||
215 | $itemEle->addOptionArray($itemsObj); |
||
216 | $whoEle = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_POSTEDBY, 'options[4]', $options[4]); |
||
217 | $comEle = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_COMMENTS, 'options[5]', $options[5]); |
||
218 | $typeEle = new \XoopsFormSelect(_MB_PUBLISHER_DISPLAY_TYPE, 'options[6]', $options[6]); |
||
219 | $typeEle->addOptionArray( |
||
220 | [ |
||
221 | 'block' => _MB_PUBLISHER_DISPLAY_TYPE_BLOCK, |
||
222 | 'bullet' => _MB_PUBLISHER_DISPLAY_TYPE_BULLET, |
||
223 | ] |
||
224 | ); |
||
225 | $truncateEle = new \XoopsFormText(_MB_PUBLISHER_TRUNCATE, 'options[7]', 4, 255, $options[7]); |
||
226 | $imageEle = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_CATIMAGE, 'options[8]', $options[8]); |
||
227 | $sortEle = new \XoopsFormSelect(_MI_PUBLISHER_ORDERBY, 'options[9]', $options[9]); |
||
228 | $sortEle->addOptionArray( |
||
229 | [ |
||
230 | 'title' => _MI_PUBLISHER_ORDERBY_TITLE, |
||
231 | 'date' => _MI_PUBLISHER_ORDERBY_DATE, |
||
232 | 'counter' => _MI_PUBLISHER_ORDERBY_HITS, |
||
233 | 'rating' => _MI_PUBLISHER_ORDERBY_RATING, |
||
234 | 'votes' => _MI_PUBLISHER_ORDERBY_VOTES, |
||
235 | 'comments' => _MI_PUBLISHER_ORDERBY_COMMENTS, |
||
236 | 'weight' => _MI_PUBLISHER_ORDERBY_WEIGHT, |
||
237 | ] |
||
238 | ); |
||
239 | $dispMoreEle = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_MORELINK, 'options[10]', $options[10]); |
||
240 | $readsEle = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_READ, 'options[11]', $options[11]); |
||
241 | $dispImage = new \XoopsFormRadioYN(_MB_PUBLISHER_IMGDISPLAY, 'options[12]', $options[12]); |
||
242 | $dispDate = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_POSTTIME, 'options[13]', $options[13]); |
||
243 | $dispCategory = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_TOPICLINK, 'options[14]', $options[14]); |
||
244 | $dispAdminlink = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_ADMINLINK, 'options[15]', $options[15]); |
||
245 | $dispReadmore = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_READ_FULLITEM, 'options[16]', $options[16]); |
||
246 | |||
247 | $form->addElement($autoEle); |
||
248 | $form->addElement($countEle); |
||
249 | $form->addElement($catEle); |
||
250 | $form->addElement($itemEle); |
||
251 | $form->addElement($whoEle); |
||
252 | $form->addElement($comEle); |
||
253 | $form->addElement($typeEle); |
||
254 | $form->addElement($truncateEle); |
||
255 | $form->addElement($imageEle); |
||
256 | $form->addElement($sortEle); |
||
257 | $form->addElement($dispMoreEle); |
||
258 | $form->addElement($readsEle); |
||
259 | $form->addElement($dispImage); |
||
260 | $form->addElement($dispDate); |
||
261 | $form->addElement($dispCategory); |
||
262 | $form->addElement($dispAdminlink); |
||
263 | $form->addElement($dispReadmore); |
||
264 | |||
265 | return $form->render(); |
||
266 | } |
||
267 |