Conditions | 36 |
Paths | > 20000 |
Total Lines | 217 |
Code Lines | 135 |
Lines | 20 |
Ratio | 9.22 % |
Changes | 2 | ||
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 |
||
32 | function publisher_latest_news_show($options) |
||
33 | { |
||
34 | $block = array(); |
||
35 | |||
36 | xoops_loadLanguage('main', 'publisher'); |
||
37 | $publisher = PublisherPublisher::getInstance(); |
||
38 | |||
39 | $start = $options[0]; // You can show articles from specified range |
||
40 | $limit = $options[1]; |
||
41 | $columnCount = $options[2]; |
||
42 | $letters = $options[3]; |
||
43 | $selectedStories = $options[4]; |
||
44 | $sort = $options[9]; |
||
45 | $order = publisherGetOrderBy($sort); |
||
46 | $imgWidth = $options[11]; |
||
47 | $imgHeight = $options[12]; |
||
48 | $border = $options[13]; |
||
49 | $bordercolor = $options[14]; |
||
50 | |||
51 | $block['spec']['columnwidth'] = (int)(1 / $columnCount * 100); |
||
52 | |||
53 | $allcats = false; |
||
54 | if (!isset($options[29])) { |
||
55 | $allcats = true; |
||
56 | } elseif (in_array(0, explode(',', $options[29]))) { |
||
57 | $allcats = true; |
||
58 | } |
||
59 | |||
60 | // creating the ITEM objects that belong to the selected category |
||
61 | View Code Duplication | if ($allcats) { |
|
62 | $criteria = null; |
||
63 | } else { |
||
64 | $criteria = new CriteriaCompo(); |
||
65 | $criteria->add(new Criteria('categoryid', '(' . $options[29] . ')', 'IN')); |
||
66 | } |
||
67 | |||
68 | // Use specific ITEMS |
||
69 | if ($selectedStories != 0) { |
||
70 | unset($criteria); //removes category option |
||
71 | $criteria = new CriteriaCompo(); |
||
72 | $criteria->add(new Criteria('itemid', '(' . $selectedStories . ')', 'IN')); |
||
73 | } |
||
74 | |||
75 | $itemsObj = $publisher->getHandler('item')->getItems($limit, $start, array(PublisherConstants::PUBLISHER_STATUS_PUBLISHED), -1, $sort, $order, '', true, $criteria, 'itemid'); |
||
76 | |||
77 | $scount = count($itemsObj); |
||
78 | |||
79 | if ($scount == 0) { |
||
80 | return false; |
||
81 | } |
||
82 | $k = 0; |
||
83 | $columns = array(); |
||
84 | |||
85 | foreach ($itemsObj as $itemid => $itemObj) { |
||
86 | $item = array(); |
||
87 | $item['itemurl'] = $itemObj->getItemUrl(); |
||
88 | $item['title'] = $itemObj->getItemLink(); |
||
89 | $item['alt'] = strip_tags($itemObj->getItemLink()); |
||
90 | $mainImage = $itemObj->getMainImage(); |
||
91 | // check to see if GD function exist |
||
92 | if (!function_exists('imagecreatetruecolor')) { |
||
93 | $item['item_image'] = $mainImage['image_path']; |
||
94 | } else { |
||
95 | $item['item_image'] = PUBLISHER_URL . '/thumb.php?src=' . $mainImage['image_path'] . '&w=' . $imgWidth; // No $imgHeight for autoheight option |
||
96 | } |
||
97 | $item['text'] = $itemObj->getBlockSummary($letters); |
||
98 | |||
99 | $item = $itemObj->getMainImage($item); //returns an array |
||
100 | |||
101 | $lsHeight = ''; |
||
102 | if ($options[12] != 0) { |
||
103 | $lsHeight = 'height="' . $imgHeight . '" '; |
||
104 | } // set height = 0 in block option for auto height |
||
105 | |||
106 | if ($options[15] === 'LEFT') { |
||
107 | $imgPosition = 'float: left'; |
||
108 | $lsMargin = '-right'; |
||
109 | } |
||
110 | |||
111 | if ($options[15] === 'CENTER') { |
||
112 | $imgPosition = 'text-align:center'; |
||
113 | $lsMargin = ''; |
||
114 | } |
||
115 | |||
116 | if ($options[15] === 'RIGHT') { |
||
117 | $imgPosition = 'float: right'; |
||
118 | $lsMargin = '-left'; |
||
119 | } |
||
120 | |||
121 | //Image |
||
122 | if ($options[10] == 1 && $item['image_path'] != '') { |
||
123 | $startdiv = '<div style="' . $imgPosition . '"><a href="' . $item['itemurl'] . '">'; |
||
124 | $style = 'style="margin' . $lsMargin . ': 10px; padding: 2px; border: ' . $border . 'px solid #' . $bordercolor . '"'; |
||
125 | $enddiv = 'width="' . $imgWidth . '" ' . $lsHeight . '/></a></div>'; |
||
126 | $image = $startdiv . '<img ' . $style . ' src="' . $item['item_image'] . '" alt="' . $item['image_name'] . '" ' . $enddiv; |
||
127 | |||
128 | $item['image'] = $image; |
||
129 | } |
||
130 | |||
131 | if (is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->isAdmin(-1)) { |
||
132 | $item['admin'] = "<a href='" . PUBLISHER_URL . '/submit.php?itemid=' . $itemObj->itemid() . "'><img src='" . PUBLISHER_URL . "/assets/images/links/edit.gif'" . " title='" . _CO_PUBLISHER_EDIT . "' alt='" . _CO_PUBLISHER_EDIT . "' /></a> "; |
||
133 | $item['admin'] .= "<a href='" . PUBLISHER_URL . '/admin/item.php?op=del&itemid=' . $itemObj->itemid() . "'><img src='" . PUBLISHER_URL . "/assets/images/links/delete.png'" . " title='" . _CO_PUBLISHER_DELETE . "' alt='" . _CO_PUBLISHER_DELETE . "' /></a>"; |
||
134 | } else { |
||
135 | $item['admin'] = ''; |
||
136 | } |
||
137 | |||
138 | $block['topiclink'] = ''; |
||
139 | /* |
||
140 | if ($options[16] == 1) { |
||
141 | $block['topiclink'] = '| <a href="'.XOOPS_URL.'/modules/news/topics_directory.php">'._AM_NEWS_TOPICS_DIRECTORY.'</a> '; |
||
142 | } |
||
143 | */ |
||
144 | $block['archivelink'] = ''; |
||
145 | View Code Duplication | if ($options[17] == 1) { |
|
146 | $block['archivelink'] = '| <a href="' . PUBLISHER_URL . '/archive.php">' . _MB_PUBLISHER_ARCHIVE . '</a> '; |
||
147 | } |
||
148 | |||
149 | //TODO: Should we not show link to Anonymous? |
||
150 | $block['submitlink'] = ''; |
||
151 | if ($options[18] == 1 && $GLOBALS['xoopsUser']) { |
||
152 | $block['submitlink'] = '| <a href="' . PUBLISHER_URL . '/submit.php">' . _MB_PUBLISHER_SUBMITNEWS . '</a> '; |
||
153 | } |
||
154 | |||
155 | $item['poster'] = ''; |
||
156 | if ($options[19] == 1) { |
||
157 | $item['poster'] = _MB_PUBLISHER_POSTER . ' ' . $itemObj->posterName(); |
||
158 | } |
||
159 | |||
160 | $item['posttime'] = ''; |
||
161 | if ($options[20] == 1) { |
||
162 | $item['posttime'] = _ON . ' ' . $itemObj->getDatesub(); |
||
163 | } |
||
164 | |||
165 | $item['topic_title'] = ''; |
||
166 | if ($options[21] == 1) { |
||
167 | $item['topic_title'] = $itemObj->getCategoryLink() . _MB_PUBLISHER_SP; |
||
168 | } |
||
169 | |||
170 | $item['read'] = ''; |
||
171 | if ($options[22] == 1) { |
||
172 | $item['read'] = ' (' . $itemObj->counter() . ' ' . _READS . ')'; |
||
173 | } |
||
174 | |||
175 | $item['more'] = ''; |
||
176 | if ($itemObj->body() != '' || $itemObj->comments() > 0) { |
||
177 | $item['more'] = '<a class="publisher_spotlight_readmore" href="' . $itemObj->getItemUrl() . '">' . _MB_PUBLISHER_READMORE . '</a>'; |
||
178 | } |
||
179 | |||
180 | $comments = $itemObj->comments(); |
||
181 | if ($options[23] == 1) { |
||
182 | if ($comments > 0) { |
||
183 | //shows 1 comment instead of 1 comm. if comments ==1 |
||
184 | //langugage file modified accordingly |
||
185 | if ($comments == 1) { |
||
186 | $item['comment'] = ' ' . _MB_PUBLISHER_ONECOMMENT . ' '; |
||
187 | } else { |
||
188 | $item['comment'] = ' ' . $comments . ' ' . _MB_PUBLISHER_COMMENTS . ' '; |
||
189 | } |
||
190 | } else { |
||
191 | $item['comment'] = ' ' . _MB_PUBLISHER_NO_COMMENTS . ' '; |
||
192 | } |
||
193 | } |
||
194 | |||
195 | $item['print'] = ''; |
||
196 | View Code Duplication | if ($options[24] == 1) { |
|
197 | $item['print'] = '<a href="' . PublisherSeo::generateUrl('print', $itemObj->itemid(), $itemObj->short_url()) . '" rel="nofollow"><img src="' . PUBLISHER_URL . '/assets/images/links/print.gif" title="' . _CO_PUBLISHER_PRINT . '" alt="' . _CO_PUBLISHER_PRINT . '" /></a> '; |
||
198 | } |
||
199 | |||
200 | $item['pdf'] = ''; |
||
201 | View Code Duplication | if ($publisher->getConfig('display_pdf')) { |
|
202 | if ($options[25] == 1) { |
||
203 | $item['pdf'] = "<a href='" . PUBLISHER_URL . '/makepdf.php?itemid=' . $itemObj->itemid() . "' rel='nofollow'><img src='" . PUBLISHER_URL . "/assets/images/links/pdf.gif' title='" . _CO_PUBLISHER_PDF . "' alt='" . _CO_PUBLISHER_PDF . "' /></a> "; |
||
204 | } |
||
205 | } |
||
206 | $item['email'] = ''; |
||
207 | if ($options[26] == 1 && xoops_isActiveModule('tellafriend')) { |
||
208 | $subject = sprintf(_CO_PUBLISHER_INTITEMFOUND, $GLOBALS['xoopsConfig']['sitename']); |
||
209 | $subject = $itemObj->convertForJapanese($subject); |
||
210 | $maillink = publisherTellAFriend($subject); |
||
211 | |||
212 | $item['email'] = '<a href="' . $maillink . '"><img src="' . PUBLISHER_URL . '/assets/images/links/friend.gif" title="' . _CO_PUBLISHER_MAIL . '" alt="' . _CO_PUBLISHER_MAIL . '" /></a> '; |
||
213 | } |
||
214 | |||
215 | $block['morelink'] = ''; |
||
216 | View Code Duplication | if ($options[27] == 1) { |
|
217 | $block['morelink'] = '<a href="' . PUBLISHER_URL . '/index.php">' . _MB_PUBLISHER_MORE_ITEMS . '</a> '; |
||
218 | } |
||
219 | |||
220 | $block['latestnews_scroll'] = false; |
||
221 | if ($options[5] == 1) { |
||
222 | $block['latestnews_scroll'] = true; |
||
223 | } |
||
224 | |||
225 | $block['scrollheight'] = $options[6]; |
||
226 | $block['scrollspeed'] = $options[7]; |
||
227 | $block['scrolldir'] = $options[8]; |
||
228 | |||
229 | $block['template'] = $options[28]; |
||
230 | |||
231 | $block['imgwidth'] = $options[11]; |
||
232 | $block['imgheight'] = $options[12]; |
||
233 | |||
234 | $block['letters'] = $letters; |
||
235 | |||
236 | $columns[$k][] = $item; |
||
237 | ++$k; |
||
238 | |||
239 | if ($k == $columnCount) { |
||
240 | $k = 0; |
||
241 | } |
||
242 | } |
||
243 | |||
244 | unset($item); |
||
245 | $block['columns'] = $columns; |
||
246 | |||
247 | return $block; |
||
248 | } |
||
249 | |||
448 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.