| Conditions | 12 |
| Paths | 33 |
| Total Lines | 53 |
| Code Lines | 39 |
| 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 |
||
| 17 | function b_arts_rated($options) |
||
| 18 | { |
||
| 19 | $myts = \MyTextSanitizer:: getInstance(); |
||
| 20 | $helper = \XoopsModules\Soapbox\Helper::getInstance(); |
||
|
|
|||
| 21 | $block_outdata = []; |
||
| 22 | $module_name = 'soapbox'; |
||
| 23 | $moduleHandler = xoops_getHandler('module'); |
||
| 24 | $soapModule = $moduleHandler->getByDirname($module_name); |
||
| 25 | if (!is_object($soapModule)) { |
||
| 26 | return null; |
||
| 27 | } |
||
| 28 | $hModConfig = xoops_getHandler('config'); |
||
| 29 | $module_id = $soapModule->getVar('mid'); |
||
| 30 | $soapConfig = $hModConfig->getConfigsByCat(0, $module_id); |
||
| 31 | //------------------------------------- |
||
| 32 | if (!in_array($options[0], ['datesub', 'weight', 'counter', 'rating', 'headline'], true)) { |
||
| 33 | $options[0] = 'datesub'; |
||
| 34 | } |
||
| 35 | $sortorder = 'DESC'; |
||
| 36 | if ('weight' === $options[0]) { |
||
| 37 | $sortorder = 'ASC'; |
||
| 38 | } |
||
| 39 | /** @var \XoopsModules\Soapbox\EntrygetHandler $entrydataHandler */ |
||
| 40 | $entrydataHandler = new \XoopsModules\Soapbox\EntrygetHandler(); |
||
| 41 | $entryobArray = $entrydataHandler->getArticlesAllPermcheck((int)$options[1], 0, true, true, 0, 0, 1, $options[0], $sortorder, null, null, false, false); |
||
| 42 | if (empty($entryobArray) || 0 === count($entryobArray)) { |
||
| 43 | return $block_outdata; |
||
| 44 | } |
||
| 45 | //------------------------------------- |
||
| 46 | foreach ($entryobArray as $_entryob) { |
||
| 47 | if (is_object($_entryob)) { |
||
| 48 | //----------- |
||
| 49 | $newarts['linktext'] = xoops_substr($_entryob->getVar('headline'), 0, (int)$options[2]); |
||
| 50 | $newarts['id'] = $_entryob->getVar('articleID'); |
||
| 51 | $newarts['dir'] = $module_name; |
||
| 52 | $newarts['date'] = $myts->htmlSpecialChars(formatTimestamp($_entryob->getVar('datesub'), $soapConfig['dateformat'])); |
||
| 53 | if ('datesub' === $options[0]) { |
||
| 54 | $newarts['new'] = $myts->htmlSpecialChars(formatTimestamp($_entryob->getVar('datesub'), $soapConfig['dateformat'])); |
||
| 55 | } elseif ('counter' === $options[0]) { |
||
| 56 | $newarts['new'] = $_entryob->getVar('counter'); |
||
| 57 | } elseif ('weight' === $options[0]) { |
||
| 58 | $newarts['new'] = $_entryob->getVar('weight'); |
||
| 59 | } elseif ('rating' === $options[0]) { |
||
| 60 | $newarts['new'] = number_format($_entryob->getVar('rating'), 2, '.', ''); |
||
| 61 | $newarts['votes'] = $_entryob->getVar('votes'); |
||
| 62 | } else { |
||
| 63 | $newarts['new'] = $myts->htmlSpecialChars(formatTimestamp($_entryob->getVar('datesub'), $soapConfig['dateformat'])); |
||
| 64 | } |
||
| 65 | $block_outdata['artslist'][] = $newarts; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | return $block_outdata; |
||
| 70 | } |
||
| 111 |