| Conditions | 12 |
| Paths | 24 |
| Total Lines | 105 |
| Code Lines | 75 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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); |
||
| 33 | function publisher_items_recent_show($options) |
||
| 34 | { |
||
| 35 | $helper = Helper::getInstance(); |
||
| 36 | /** @var ItemHandler $itemHandler */ |
||
| 37 | $itemHandler = $helper->getHandler('Item'); |
||
| 38 | $myts = \MyTextSanitizer::getInstance(); |
||
| 39 | |||
| 40 | $block = $newItems = []; |
||
| 41 | |||
| 42 | $selectedcatids = explode(',', $options[0]); |
||
| 43 | |||
| 44 | $allcats = false; |
||
| 45 | if (in_array(0, $selectedcatids, false)) { |
||
| 46 | $allcats = true; |
||
| 47 | } |
||
| 48 | |||
| 49 | $sort = $options[1]; |
||
| 50 | $order = Utility::getOrderBy($sort); |
||
| 51 | $limit = $options[2]; |
||
| 52 | $start = 0; |
||
| 53 | |||
| 54 | // creating the ITEM objects that belong to the selected category |
||
| 55 | if ($allcats) { |
||
| 56 | $criteria = null; |
||
| 57 | } else { |
||
| 58 | $criteria = new \CriteriaCompo(); |
||
| 59 | $criteria->add(new \Criteria('categoryid', '(' . $options[0] . ')', 'IN')); |
||
| 60 | } |
||
| 61 | |||
| 62 | $publisherIsAdmin = $helper->isUserAdmin(); |
||
| 63 | if (!$publisherIsAdmin) { |
||
| 64 | if (null === $criteria) { |
||
| 65 | $criteria = new \CriteriaCompo(); |
||
| 66 | } |
||
| 67 | $criteriaDateSub = new \Criteria('datesub', time(), '<='); |
||
| 68 | $criteria->add($criteriaDateSub); |
||
| 69 | } |
||
| 70 | |||
| 71 | $itemsObj = $itemHandler->getItems($limit, $start, [Constants::PUBLISHER_STATUS_PUBLISHED], -1, $sort, $order, '', true, $criteria, 'none'); |
||
| 72 | |||
| 73 | $totalItems = count($itemsObj); |
||
| 74 | |||
| 75 | if ($itemsObj && $totalItems > 0) { |
||
| 76 | foreach ($itemsObj as $iValue) { |
||
| 77 | $newItems['itemid'] = $iValue->itemid(); |
||
| 78 | $newItems['itemurl'] = $iValue->getItemUrl(); |
||
| 79 | $newItems['title'] = $iValue->getTitle(); |
||
| 80 | $newItems['alt'] = strip_tags($iValue->getItemLink()); |
||
| 81 | $newItems['categoryname'] = $iValue->getCategoryName(); |
||
| 82 | $newItems['categoryid'] = $iValue->categoryid(); |
||
| 83 | $newItems['date'] = $iValue->getDatesub(); |
||
| 84 | $newItems['poster'] = $iValue->getLinkedPosterName(); |
||
| 85 | $newItems['itemlink'] = $iValue->getItemLink(false, $options[3] ?? 65); |
||
| 86 | $newItems['categorylink'] = $iValue->getCategoryLink(); |
||
| 87 | $newItems['hits'] = ' ' . $iValue->counter() . ' ' . _READS; |
||
| 88 | $newItems['summary'] = $iValue->getBlockSummary(300, true); //show complete summary but truncate to 300 if only body available |
||
| 89 | |||
| 90 | $mainImage = $iValue->getMainImage(); // check to see if GD function exist |
||
| 91 | if (empty($mainImage['image_path'])) { |
||
| 92 | $mainImage['image_path'] = PUBLISHER_URL . '/assets/images/default_image.jpg'; |
||
| 93 | } |
||
| 94 | if (function_exists('imagecreatetruecolor')) { |
||
| 95 | $newItems['item_image'] = PUBLISHER_URL . '/thumb.php?src=' . $mainImage['image_path']; |
||
| 96 | $newItems['image_path'] = $mainImage['image_path']; |
||
| 97 | } else { |
||
| 98 | $newItems['item_image'] = $mainImage['image_path']; |
||
| 99 | } |
||
| 100 | $newItems['cancomment'] = $iValue->cancomment(); |
||
| 101 | $comments = $iValue->comments(); |
||
| 102 | if ($comments > 0) { |
||
| 103 | //shows 1 comment instead of 1 comm. if comments ==1 |
||
| 104 | //langugage file modified accordingly |
||
| 105 | if (1 == $comments) { |
||
| 106 | $newItems['comment'] = ' ' . _MB_PUBLISHER_ONECOMMENT . ' '; |
||
| 107 | } else { |
||
| 108 | $newItems['comment'] = ' ' . $comments . ' ' . _MB_PUBLISHER_COMMENTS . ' '; |
||
| 109 | } |
||
| 110 | } else { |
||
| 111 | $newItems['comment'] = ' ' . _MB_PUBLISHER_NO_COMMENTS . ' '; |
||
| 112 | } |
||
| 113 | |||
| 114 | $block['items'][] = $newItems; |
||
| 115 | } |
||
| 116 | $block['publisher_url'] = PUBLISHER_URL; |
||
| 117 | $block['lang_title'] = _MB_PUBLISHER_ITEMS; |
||
| 118 | $block['lang_category'] = _MB_PUBLISHER_CATEGORY; |
||
| 119 | $block['lang_poster'] = _MB_PUBLISHER_POSTEDBY; |
||
| 120 | $block['lang_date'] = _MB_PUBLISHER_DATE; |
||
| 121 | $moduleName = $myts->displayTarea( |
||
| 122 | $helper->getModule() |
||
|
|
|||
| 123 | ->getVar('name') |
||
| 124 | ); |
||
| 125 | $block['lang_visitItem'] = _MB_PUBLISHER_VISITITEM . ' ' . $moduleName; |
||
| 126 | |||
| 127 | $block['show_image'] = $options[4] ?? 0; |
||
| 128 | $block['show_summary'] = $options[5] ?? 0; |
||
| 129 | $block['show_category'] = $options[6] ?? 0; |
||
| 130 | $block['show_poster'] = $options[7] ?? 0; |
||
| 131 | $block['show_date'] = $options[8] ?? 0; |
||
| 132 | $block['show_hits'] = $options[9] ?? 0; |
||
| 133 | $block['show_comment'] = $options[10] ?? 0; |
||
| 134 | $block['show_morelink'] = $options[11] ?? 0; |
||
| 135 | } |
||
| 136 | |||
| 137 | return $block; |
||
| 138 | } |
||
| 187 |