Conditions | 5 |
Paths | 8 |
Total Lines | 53 |
Code Lines | 36 |
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 |
||
37 | function publisher_items_recent_show($options) |
||
38 | { |
||
39 | $helper = Helper::getInstance(); |
||
40 | $myts = Sanitizer::getInstance(); |
||
41 | |||
42 | $block = []; |
||
43 | |||
44 | $selectedcatids = explode(',', $options[0]); |
||
45 | |||
46 | if (in_array(0, $selectedcatids)) { |
||
47 | $allcats = true; |
||
48 | } else { |
||
49 | $allcats = false; |
||
50 | } |
||
51 | |||
52 | $sort = $options[1]; |
||
53 | $order = Publisher\Utils::getOrderBy($sort); |
||
54 | $limit = $options[2]; |
||
55 | $start = 0; |
||
56 | |||
57 | // creating the ITEM objects that belong to the selected category |
||
58 | if ($allcats) { |
||
59 | $criteria = null; |
||
60 | } else { |
||
61 | $criteria = new CriteriaCompo(); |
||
62 | $criteria->add(new Criteria('categoryid', '(' . $options[0] . ')', 'IN')); |
||
63 | } |
||
64 | $itemsObj = $helper->getItemHandler()->getItems($limit, $start, [_PUBLISHER_STATUS_PUBLISHED], -1, $sort, $order, '', true, $criteria, true); |
||
65 | |||
66 | if ($itemsObj) { |
||
67 | foreach ($itemsObj as $iValue) { |
||
68 | |||
69 | $newItems['itemid'] = $iValue->getVar('itemid'); |
||
70 | $newItems['title'] = $iValue->title(); |
||
71 | $newItems['categoryname'] = $iValue->getCategoryName(); |
||
72 | $newItems['categoryid'] = $iValue->getVar('categoryid'); |
||
73 | $newItems['date'] = $iValue->datesub(); |
||
74 | $newItems['poster'] = $iValue->linkedPosterName(); |
||
75 | $newItems['itemlink'] = $iValue->getItemLink(false, $options[3] ?? 65); |
||
76 | $newItems['categorylink'] = $iValue->getCategoryLink(); |
||
77 | |||
78 | $block['items'][] = $newItems; |
||
79 | } |
||
80 | |||
81 | $block['lang_title'] = _MB_PUBLISHER_ITEMS; |
||
82 | $block['lang_category'] = _MB_PUBLISHER_CATEGORY; |
||
83 | $block['lang_poster'] = _MB_PUBLISHER_POSTEDBY; |
||
84 | $block['lang_date'] = _MB_PUBLISHER_DATE; |
||
85 | $modulename = $myts->displayTarea($helper->getModule()->getVar('name')); |
||
86 | $block['lang_visitItem'] = _MB_PUBLISHER_VISITITEM . ' ' . $modulename; |
||
87 | } |
||
88 | |||
89 | return $block; |
||
90 | } |
||
117 |