Conditions | 26 |
Paths | 360 |
Total Lines | 150 |
Code Lines | 121 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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); |
||
35 | function publisher_items_spot_show($options) |
||
36 | { |
||
37 | // global $xoTheme; |
||
38 | $helper = Helper::getInstance(); |
||
39 | /** @var CategoryHandler $categoryHandler */ |
||
40 | $categoryHandler = $helper->getHandler('Category'); |
||
41 | /** @var ItemHandler $itemHandler */ |
||
42 | $itemHandler = $helper->getHandler('Item'); |
||
43 | xoops_loadLanguage('main', 'publisher'); |
||
44 | |||
45 | $optDisplayLast = $options[0]; |
||
46 | $optItemsCount = $options[1]; |
||
47 | $optCategoryId = $options[2]; |
||
48 | $selItems = isset($options[3]) ? explode(',', $options[3]) : ''; |
||
49 | $optDisplayPoster = $options[4]; |
||
50 | $optDisplayComment = $options[5]; |
||
51 | $optDisplayType = $options[6]; |
||
52 | $optTruncate = (int)$options[7]; |
||
53 | $optCatImage = $options[8]; |
||
54 | $optSortOrder = $options[9] ?? ''; |
||
55 | $optBtnDisplayMore = $options[10] ?? ''; |
||
56 | $optDisplayReads = $options[11] ?? ''; |
||
57 | $optdisplayitemimage = $options[12] ?? ''; |
||
58 | $optdisplaywhenlink = $options[13] ?? ''; |
||
59 | $optdisplaycategorylink = $options[14] ?? ''; |
||
60 | $optdisplayadminlink = $options[15] ?? ''; |
||
61 | $optdisplayreadmore = $options[16] ?? ''; |
||
62 | |||
63 | if (0 == $optCategoryId) { |
||
64 | $optCategoryId = -1; |
||
65 | } |
||
66 | $block = []; |
||
67 | if (1 == $optDisplayLast) { |
||
68 | switch ($optSortOrder) { |
||
69 | case 'title': |
||
70 | $sort = 'title'; |
||
71 | $order = 'ASC'; |
||
72 | break; |
||
73 | case 'date': |
||
74 | $sort = 'datesub'; |
||
75 | $order = 'DESC'; |
||
76 | break; |
||
77 | case 'counter': |
||
78 | $sort = 'counter'; |
||
79 | $order = 'DESC'; |
||
80 | break; |
||
81 | case 'rating': |
||
82 | $sort = 'rating'; |
||
83 | $order = 'DESC'; |
||
84 | break; |
||
85 | case 'votes': |
||
86 | $sort = 'votes'; |
||
87 | $order = 'DESC'; |
||
88 | break; |
||
89 | case 'comments': |
||
90 | $sort = 'comments'; |
||
91 | $order = 'DESC'; |
||
92 | break; |
||
93 | default: |
||
94 | $sort = 'weight'; |
||
95 | $order = 'ASC'; |
||
96 | break; |
||
97 | } |
||
98 | $itemsObj = $itemHandler->getAllPublished($optItemsCount, 0, $optCategoryId, $sort, $order, 'summary'); |
||
99 | $i = 1; |
||
100 | $itemsCount = count($itemsObj); |
||
101 | if ($itemsObj) { |
||
102 | if (-1 != $optCategoryId) { |
||
103 | /** @var Category $cat */ |
||
104 | $cat = $categoryHandler->get($optCategoryId); |
||
105 | $category['name'] = $cat->name; |
||
|
|||
106 | $category['categoryurl'] = $cat->getCategoryUrl(); |
||
107 | if ('blank.png' !== $cat->getImage()) { |
||
108 | $category['image_path'] = Utility::getImageDir('category', false) . $cat->getImage(); |
||
109 | } else { |
||
110 | $category['image_path'] = ''; |
||
111 | } |
||
112 | $block['category'] = $category; |
||
113 | } else { |
||
114 | $block['category']['categoryurl'] = XOOPS_URL . '/modules/' . PUBLISHER_DIRNAME; |
||
115 | } |
||
116 | foreach ($itemsObj as $key => $thisItem) { |
||
117 | $item = $thisItem->toArraySimple('default', 0, $optTruncate); |
||
118 | if ($i < $itemsCount) { |
||
119 | $item['showline'] = true; |
||
120 | } else { |
||
121 | $item['showline'] = false; |
||
122 | } |
||
123 | if ($optTruncate > 0) { |
||
124 | $block['truncate'] = true; |
||
125 | } |
||
126 | $block['items'][] = $item; |
||
127 | ++$i; |
||
128 | } |
||
129 | } |
||
130 | } else { |
||
131 | $i = 1; |
||
132 | if ($selItems && is_array($selItems)) { |
||
133 | $itemsCount = count($selItems); |
||
134 | foreach ($selItems as $itemId) { |
||
135 | /** @var Item $itemObj */ |
||
136 | $itemObj = $itemHandler->get($itemId); |
||
137 | if (null !== $itemObj && !$itemObj->notLoaded()) { |
||
138 | $item = $itemObj->toArraySimple(); |
||
139 | $item['who_when'] = sprintf(_MB_PUBLISHER_WHO_WHEN, $item['who'], $item['when']); |
||
140 | if ($i < $itemsCount) { |
||
141 | $item['showline'] = true; |
||
142 | } else { |
||
143 | $item['showline'] = false; |
||
144 | } |
||
145 | if ($optTruncate > 0) { |
||
146 | $block['truncate'] = true; |
||
147 | $item['summary'] = Utility::truncateHtml($item['summary'], $optTruncate); |
||
148 | } |
||
149 | $block['items'][] = $item; |
||
150 | ++$i; |
||
151 | } |
||
152 | } |
||
153 | } |
||
154 | } |
||
155 | if (!isset($block['items']) || 0 == count($block['items'])) { |
||
156 | return false; |
||
157 | } |
||
158 | $block['lang_reads'] = _MB_PUBLISHER_READS; |
||
159 | $block['lang_comments'] = _MB_PUBLISHER_COMMENTS; |
||
160 | $block['lang_readmore'] = _MB_PUBLISHER_READMORE; |
||
161 | $block['lang_poster'] = _MB_PUBLISHER_POSTEDBY; |
||
162 | $block['lang_date'] = _MB_PUBLISHER_ON; |
||
163 | $block['lang_category'] = _MB_PUBLISHER_CATEGORY; |
||
164 | |||
165 | $block['display_whowhen_link'] = $optDisplayPoster; |
||
166 | $block['display_who_link'] = $optDisplayPoster; |
||
167 | $block['display_comment_link'] = $optDisplayComment; |
||
168 | $block['display_type'] = $optDisplayType; |
||
169 | $block['display_reads'] = $optDisplayReads; |
||
170 | $block['display_cat_image'] = $optCatImage; |
||
171 | $block['display_item_image'] = $optdisplayitemimage; |
||
172 | $block['display_when_link'] = $optdisplaywhenlink; |
||
173 | $block['display_categorylink'] = $optdisplaycategorylink; |
||
174 | $block['display_adminlink'] = $optdisplayadminlink; |
||
175 | $block['display_readmore'] = $optdisplayreadmore; |
||
176 | |||
177 | if ($optBtnDisplayMore) { |
||
178 | $block['lang_displaymore'] = _MB_PUBLISHER_MORE_ITEMS; |
||
179 | } |
||
180 | |||
181 | $block['publisher_url'] = PUBLISHER_URL; |
||
182 | $GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/modules/' . PUBLISHER_DIRNAME . '/assets/css/' . PUBLISHER_DIRNAME . '.css'); |
||
183 | |||
184 | return $block; |
||
185 | } |
||
267 |