Conditions | 11 |
Paths | 80 |
Total Lines | 120 |
Code Lines | 91 |
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 |
||
213 | public static function editCategory($showmenu = false, $categoryId = 0, $nbSubCats = 4, $categoryObj = null) |
||
214 | { |
||
215 | $publisher = PublisherPublisher::getInstance(); |
||
216 | |||
217 | // if there is a parameter, and the id exists, retrieve data: we're editing a category |
||
218 | if ($categoryId != 0) { |
||
219 | // Creating the category object for the selected category |
||
220 | $categoryObj = $publisher->getHandler('category')->get($categoryId); |
||
221 | if ($categoryObj->notLoaded()) { |
||
222 | redirect_header('category.php', 1, _AM_PUBLISHER_NOCOLTOEDIT); |
||
223 | // exit(); |
||
224 | } |
||
225 | } else { |
||
226 | if (!$categoryObj) { |
||
227 | $categoryObj = $publisher->getHandler('category')->create(); |
||
228 | } |
||
229 | } |
||
230 | |||
231 | if ($categoryId != 0) { |
||
232 | echo "<br />\n"; |
||
233 | publisherOpenCollapsableBar('edittable', 'edittableicon', _AM_PUBLISHER_EDITCOL, _AM_PUBLISHER_CATEGORY_EDIT_INFO); |
||
234 | } else { |
||
235 | publisherOpenCollapsableBar('createtable', 'createtableicon', _AM_PUBLISHER_CATEGORY_CREATE, _AM_PUBLISHER_CATEGORY_CREATE_INFO); |
||
236 | } |
||
237 | |||
238 | $sform = $categoryObj->getForm($nbSubCats); |
||
239 | $sform->display(); |
||
240 | |||
241 | if (!$categoryId) { |
||
242 | publisherCloseCollapsableBar('createtable', 'createtableicon'); |
||
243 | } else { |
||
244 | publisherCloseCollapsableBar('edittable', 'edittableicon'); |
||
245 | } |
||
246 | |||
247 | //Added by fx2024 |
||
248 | if ($categoryId) { |
||
249 | $selCat = $categoryId; |
||
250 | |||
251 | publisherOpenCollapsableBar('subcatstable', 'subcatsicon', _AM_PUBLISHER_SUBCAT_CAT, _AM_PUBLISHER_SUBCAT_CAT_DSC); |
||
252 | // Get the total number of sub-categories |
||
253 | $categoriesObj = $publisher->getHandler('category')->get($selCat); |
||
254 | $totalsubs = $publisher->getHandler('category')->getCategoriesCount($selCat); |
||
255 | // creating the categories objects that are published |
||
256 | $subcatsObj = $publisher->getHandler('category')->getCategories(0, 0, $categoriesObj->categoryid()); |
||
257 | $totalSCOnPage = count($subcatsObj); |
||
258 | echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>"; |
||
259 | echo '<tr>'; |
||
260 | echo "<td width='60' class='bg3' align='left'><strong>" . _AM_PUBLISHER_CATID . '</strong></td>'; |
||
261 | echo "<td width='20%' class='bg3' align='left'><strong>" . _AM_PUBLISHER_CATCOLNAME . '</strong></td>'; |
||
262 | echo "<td class='bg3' align='left'><strong>" . _AM_PUBLISHER_SUBDESCRIPT . '</strong></td>'; |
||
263 | echo "<td width='60' class='bg3' align='right'><strong>" . _AM_PUBLISHER_ACTION . '</strong></td>'; |
||
264 | echo '</tr>'; |
||
265 | if ($totalsubs > 0) { |
||
266 | foreach ($subcatsObj as $subcat) { |
||
267 | $modify = "<a href='category.php?op=mod&categoryid=" . $subcat->categoryid() . "'><img src='" . XOOPS_URL . '/modules/' . $publisher->getModule()->dirname() . "/assets/images/links/edit.gif' title='" . _AM_PUBLISHER_MODIFY . "' alt='" . _AM_PUBLISHER_MODIFY . "' /></a>"; |
||
268 | $delete = "<a href='category.php?op=del&categoryid=" . $subcat->categoryid() . "'><img src='" . XOOPS_URL . '/modules/' . $publisher->getModule()->dirname() . "/assets/images/links/delete.png' title='" . _AM_PUBLISHER_DELETE . "' alt='" . _AM_PUBLISHER_DELETE . "' /></a>"; |
||
269 | echo '<tr>'; |
||
270 | echo "<td class='head' align='left'>" . $subcat->categoryid() . '</td>'; |
||
271 | echo "<td class='even' align='left'><a href='" . XOOPS_URL . '/modules/' . $publisher->getModule()->dirname() . '/category.php?categoryid=' . $subcat->categoryid() . '&parentid=' . $subcat->parentid() . "'>" . $subcat->name() . '</a></td>'; |
||
272 | echo "<td class='even' align='left'>" . $subcat->description() . '</td>'; |
||
273 | echo "<td class='even' align='right'> {$modify} {$delete} </td>"; |
||
274 | echo '</tr>'; |
||
275 | } |
||
276 | // unset($subcat); |
||
277 | } else { |
||
278 | echo '<tr>'; |
||
279 | echo "<td class='head' align='center' colspan= '7'>" . _AM_PUBLISHER_NOSUBCAT . '</td>'; |
||
280 | echo '</tr>'; |
||
281 | } |
||
282 | echo "</table>\n"; |
||
283 | echo "<br />\n"; |
||
284 | publisherCloseCollapsableBar('subcatstable', 'subcatsicon'); |
||
285 | |||
286 | publisherOpenCollapsableBar('bottomtable', 'bottomtableicon', _AM_PUBLISHER_CAT_ITEMS, _AM_PUBLISHER_CAT_ITEMS_DSC); |
||
287 | $startitem = XoopsRequest::getInt('startitem'); |
||
288 | // Get the total number of published ITEMS |
||
289 | $totalitems = $publisher->getHandler('item')->getItemsCount($selCat, array(PublisherConstants::PUBLISHER_STATUS_PUBLISHED)); |
||
290 | // creating the items objects that are published |
||
291 | $itemsObj = $publisher->getHandler('item')->getAllPublished($publisher->getConfig('idxcat_perpage'), $startitem, $selCat); |
||
292 | $totalitemsOnPage = count($itemsObj); |
||
293 | $allcats = $publisher->getHandler('category')->getObjects(null, true); |
||
294 | echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>"; |
||
295 | echo '<tr>'; |
||
296 | echo "<td width='40' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ITEMID . '</strong></td>'; |
||
297 | echo "<td width='20%' class='bg3' align='left'><strong>" . _AM_PUBLISHER_ITEMCOLNAME . '</strong></td>'; |
||
298 | echo "<td class='bg3' align='left'><strong>" . _AM_PUBLISHER_ITEMDESC . '</strong></td>'; |
||
299 | echo "<td width='90' class='bg3' align='center'><strong>" . _AM_PUBLISHER_CREATED . '</strong></td>'; |
||
300 | echo "<td width='60' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ACTION . '</strong></td>'; |
||
301 | echo '</tr>'; |
||
302 | if ($totalitems > 0) { |
||
303 | for ($i = 0; $i < $totalitemsOnPage; ++$i) { |
||
304 | $categoryObj = $allcats[$itemsObj[$i]->categoryid()]; |
||
305 | $modify = "<a href='item.php?op=mod&itemid=" . $itemsObj[$i]->itemid() . "'><img src='" . XOOPS_URL . '/modules/' . $publisher->getModule()->dirname() . "/assets/images/links/edit.gif' title='" . _AM_PUBLISHER_EDITITEM . "' alt='" . _AM_PUBLISHER_EDITITEM . "' /></a>"; |
||
306 | $delete = "<a href='item.php?op=del&itemid=" . $itemsObj[$i]->itemid() . "'><img src='" . XOOPS_URL . '/modules/' . $publisher->getModule()->dirname() . "/assets/images/links/delete.png' title='" . _AM_PUBLISHER_DELETEITEM . "' alt='" . _AM_PUBLISHER_DELETEITEM . "'/></a>"; |
||
307 | echo '<tr>'; |
||
308 | echo "<td class='head' align='center'>" . $itemsObj[$i]->itemid() . '</td>'; |
||
309 | echo "<td class='even' align='left'>" . $categoryObj->name() . '</td>'; |
||
310 | echo "<td class='even' align='left'>" . $itemsObj[$i]->getitemLink() . '</td>'; |
||
311 | echo "<td class='even' align='center'>" . $itemsObj[$i]->getDatesub('s') . '</td>'; |
||
312 | echo "<td class='even' align='center'> $modify $delete </td>"; |
||
313 | echo '</tr>'; |
||
314 | } |
||
315 | } else { |
||
316 | $itemid = -1; |
||
317 | echo '<tr>'; |
||
318 | echo "<td class='head' align='center' colspan= '7'>" . _AM_PUBLISHER_NOITEMS . '</td>'; |
||
319 | echo '</tr>'; |
||
320 | } |
||
321 | echo "</table>\n"; |
||
322 | echo "<br />\n"; |
||
323 | $parentid = XoopsRequest::getInt('parentid', 0, 'GET'); |
||
324 | $pagenavExtraArgs = "op=mod&categoryid=$selCat&parentid=$parentid"; |
||
325 | xoops_load('XoopsPageNav'); |
||
326 | $pagenav = new XoopsPageNav($totalitems, $publisher->getConfig('idxcat_perpage'), $startitem, 'startitem', $pagenavExtraArgs); |
||
327 | echo '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>'; |
||
328 | echo "<input type='button' name='button' onclick=\"location='item.php?op=mod&categoryid=" . $selCat . "'\" value='" . _AM_PUBLISHER_CREATEITEM . "'> "; |
||
329 | echo '</div>'; |
||
330 | } |
||
331 | //end of fx2024 code |
||
332 | } |
||
333 | } |
||
334 |
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.