| Conditions | 19 |
| Paths | 48 |
| Total Lines | 92 |
| Code Lines | 67 |
| 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 |
||
| 33 | function publisher_items_spot_show($options) |
||
| 34 | { |
||
| 35 | // global $xoTheme; |
||
| 36 | /** @var Publisher\Helper $helper */ |
||
| 37 | $helper = Publisher\Helper::getInstance(); |
||
| 38 | /** @var Publisher\CategoryHandler $categoryHandler */ |
||
| 39 | $categoryHandler = $helper->getHandler('Category'); |
||
| 40 | /** @var Publisher\ItemHandler $itemHandler */ |
||
| 41 | $itemHandler = $helper->getHandler('Item'); |
||
| 42 | |||
| 43 | $optDisplayLast = $options[0]; |
||
| 44 | $optItemsCount = $options[1]; |
||
| 45 | $optCategoryId = $options[2]; |
||
| 46 | $selItems = isset($options[3]) ? explode(',', $options[3]) : ''; |
||
| 47 | $optDisplayPoster = $options[4]; |
||
| 48 | $optDisplayComment = $options[5]; |
||
| 49 | $optDisplayType = $options[6]; |
||
| 50 | $optTruncate = (int)$options[7]; |
||
| 51 | $optCatImage = $options[8]; |
||
| 52 | if (0 == $optCategoryId) { |
||
| 53 | $optCategoryId = -1; |
||
| 54 | } |
||
| 55 | $block = []; |
||
| 56 | if (1 == $optDisplayLast) { |
||
| 57 | $itemsObj = $itemHandler->getAllPublished($optItemsCount, 0, $optCategoryId, $sort = 'datesub', $order = 'DESC', 'summary'); |
||
| 58 | $i = 1; |
||
| 59 | $itemsCount = count($itemsObj); |
||
| 60 | if ($itemsObj) { |
||
|
|
|||
| 61 | if (-1 != $optCategoryId && $optCatImage) { |
||
| 62 | /** @var Publisher\Category $cat */ |
||
| 63 | $cat = $categoryHandler->get($optCategoryId); |
||
| 64 | $category['name'] = $cat->name; |
||
| 65 | $category['categoryurl'] = $cat->getCategoryUrl(); |
||
| 66 | if ('blank.png' !== $cat->getImage()) { |
||
| 67 | $category['image_path'] = Publisher\Utility::getImageDir('category', false) . $cat->getImage(); |
||
| 68 | } else { |
||
| 69 | $category['image_path'] = ''; |
||
| 70 | } |
||
| 71 | $block['category'] = $category; |
||
| 72 | } |
||
| 73 | foreach ($itemsObj as $key => $thisItem) { |
||
| 74 | $item = $thisItem->toArraySimple('default', 0, $optTruncate); |
||
| 75 | if ($i < $itemsCount) { |
||
| 76 | $item['showline'] = true; |
||
| 77 | } else { |
||
| 78 | $item['showline'] = false; |
||
| 79 | } |
||
| 80 | if ($optTruncate > 0) { |
||
| 81 | $block['truncate'] = true; |
||
| 82 | } |
||
| 83 | $block['items'][] = $item; |
||
| 84 | ++$i; |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } else { |
||
| 88 | $i = 1; |
||
| 89 | if (is_array($selItems) && count($selItems) > 0) { |
||
| 90 | foreach ($selItems as $itemId) { |
||
| 91 | /** @var Publisher\Item $itemObj */ |
||
| 92 | $itemObj = $itemHandler->get($itemId); |
||
| 93 | if (!$itemObj->notLoaded()) { |
||
| 94 | $item = $itemObj->toArraySimple(); |
||
| 95 | $item['who_when'] = sprintf(_MB_PUBLISHER_WHO_WHEN, $itemObj->posterName, $itemObj->getDatesub); |
||
| 96 | if ($i < $itemsCount) { |
||
| 97 | $item['showline'] = true; |
||
| 98 | } else { |
||
| 99 | $item['showline'] = false; |
||
| 100 | } |
||
| 101 | if ($optTruncate > 0) { |
||
| 102 | $block['truncate'] = true; |
||
| 103 | $item['summary'] = Publisher\Utility::truncateHtml($item['summary'], $optTruncate); |
||
| 104 | } |
||
| 105 | $block['items'][] = $item; |
||
| 106 | ++$i; |
||
| 107 | } |
||
| 108 | } |
||
| 109 | } |
||
| 110 | } |
||
| 111 | if (!isset($block['items']) || 0 == count($block['items'])) { |
||
| 112 | return false; |
||
| 113 | } |
||
| 114 | $block['lang_reads'] = _MB_PUBLISHER_READS; |
||
| 115 | $block['lang_comments'] = _MB_PUBLISHER_COMMENTS; |
||
| 116 | $block['lang_readmore'] = _MB_PUBLISHER_READMORE; |
||
| 117 | $block['display_whowhen_link'] = $optDisplayPoster; |
||
| 118 | $block['display_comment_link'] = $optDisplayComment; |
||
| 119 | $block['display_type'] = $optDisplayType; |
||
| 120 | |||
| 121 | $block['publisher_url'] = PUBLISHER_URL; |
||
| 122 | $GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/modules/' . PUBLISHER_DIRNAME . '/assets/css/publisher.css'); |
||
| 123 | |||
| 124 | return $block; |
||
| 125 | } |
||
| 178 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.