| Conditions | 7 |
| Paths | 14 |
| Total Lines | 74 |
| Code Lines | 50 |
| 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_random_item_show($options) |
||
| 34 | { |
||
| 35 | $block = []; |
||
| 36 | |||
| 37 | $helper = Helper::getInstance(); |
||
| 38 | /** @var ItemHandler $itemHandler */ |
||
| 39 | $itemHandler = $helper->getHandler('Item'); |
||
| 40 | |||
| 41 | $optItemsCount = (int)$options[8]; |
||
| 42 | |||
| 43 | for ($k = 0; $k < $optItemsCount; $k++) { |
||
| 44 | $item = []; |
||
| 45 | |||
| 46 | // creating the ITEM object |
||
| 47 | $itemsObj = $itemHandler->getRandomItem('', [Constants::PUBLISHER_STATUS_PUBLISHED]); |
||
|
|
|||
| 48 | |||
| 49 | if (!is_object($itemsObj)) { |
||
| 50 | return $item; |
||
| 51 | } |
||
| 52 | |||
| 53 | $item['content'] = $itemsObj->getBlockSummary(300, true); //show complete summary but truncate to 300 if only body available |
||
| 54 | $item['id'] = $itemsObj->itemid(); |
||
| 55 | $item['url'] = $itemsObj->getItemUrl(); |
||
| 56 | $item['lang_fullitem'] = _MB_PUBLISHER_FULLITEM; |
||
| 57 | $item['lang_poster'] = _MB_PUBLISHER_POSTEDBY; |
||
| 58 | $item['lang_date'] = _MB_PUBLISHER_ON; |
||
| 59 | $item['lang_category'] = _MB_PUBLISHER_CATEGORY; |
||
| 60 | $item['lang_reads'] = _MB_PUBLISHER_HITS; |
||
| 61 | $item['titlelink'] = $itemsObj->getItemLink('titlelink'); |
||
| 62 | $item['alt'] = strip_tags($itemsObj->getItemLink()); |
||
| 63 | $item['date'] = $itemsObj->getDatesub(); |
||
| 64 | $item['poster'] = $itemsObj->getLinkedPosterName(); |
||
| 65 | $item['categorylink'] = $itemsObj->getCategoryLink(); |
||
| 66 | $item['hits'] = ' ' . $itemsObj->counter() . ' ' . _READS; |
||
| 67 | |||
| 68 | $mainImage = $itemsObj->getMainImage(); // check to see if GD function exist |
||
| 69 | if (empty($mainImage['image_path'])) { |
||
| 70 | $mainImage['image_path'] = PUBLISHER_URL . '/assets/images/default_image.jpg'; |
||
| 71 | } |
||
| 72 | if (function_exists('imagecreatetruecolor')) { |
||
| 73 | $item['item_image'] = PUBLISHER_URL . '/thumb.php?src=' . $mainImage['image_path']; |
||
| 74 | $item['image_path'] = $mainImage['image_path']; |
||
| 75 | } else { |
||
| 76 | $item['item_image'] = $mainImage['image_path']; |
||
| 77 | } |
||
| 78 | |||
| 79 | $item['cancomment'] = $itemsObj->cancomment(); |
||
| 80 | $comments = $itemsObj->comments(); |
||
| 81 | if ($comments > 0) { |
||
| 82 | //shows 1 comment instead of 1 comm. if comments ==1 |
||
| 83 | //langugage file modified accordingly |
||
| 84 | if (1 == $comments) { |
||
| 85 | $item['comment'] = ' ' . _MB_PUBLISHER_ONECOMMENT . ' '; |
||
| 86 | } else { |
||
| 87 | $item['comment'] = ' ' . $comments . ' ' . _MB_PUBLISHER_COMMENTS . ' '; |
||
| 88 | } |
||
| 89 | } else { |
||
| 90 | $item['comment'] = ' ' . _MB_PUBLISHER_NO_COMMENTS . ' '; |
||
| 91 | } |
||
| 92 | $item['display_summary'] = $options[0]; |
||
| 93 | $item['display_item_image'] = $options[1]; |
||
| 94 | $item['display_poster'] = $options[2]; |
||
| 95 | $item['display_date'] = $options[3]; |
||
| 96 | $item['display_categorylink'] = $options[4]; |
||
| 97 | $item['display_hits'] = $options[5]; |
||
| 98 | $item['display_comment'] = $options[6]; |
||
| 99 | $item['display_lang_fullitem'] = $options[7]; |
||
| 100 | |||
| 101 | // $block['items'][] = $block; |
||
| 102 | |||
| 103 | $block['items'][] = $item; |
||
| 104 | } |
||
| 105 | |||
| 106 | return $block; |
||
| 107 | } |
||
| 141 |