| Conditions | 8 |
| Paths | 12 |
| Total Lines | 63 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 29 | function b_mymodule2_articles_show($options) |
||
| 30 | { |
||
| 31 | include_once XOOPS_ROOT_PATH.'/modules/mymodule2/class/articles.php'; |
||
| 32 | $myts = MyTextSanitizer::getInstance(); |
||
| 33 | $GLOBALS['xoopsTpl']->assign('mymodule2_upload_url', MYMODULE2_UPLOAD_URL); |
||
| 34 | $block = array(); |
||
| 35 | $typeBlock = $options[0]; |
||
| 36 | $limit = $options[1]; |
||
| 37 | $lenghtTitle = $options[2]; |
||
|
|
|||
| 38 | $helper = Helper::getInstance(); |
||
| 39 | $articlesHandler = $helper->getHandler('articles'); |
||
| 40 | $criteria = new \CriteriaCompo(); |
||
| 41 | array_shift($options); |
||
| 42 | array_shift($options); |
||
| 43 | array_shift($options); |
||
| 44 | switch($typeBlock) |
||
| 45 | { |
||
| 46 | // For the block: articles last |
||
| 47 | case 'last': |
||
| 48 | //$criteria->add(new \Criteria('art_display', 1)); |
||
| 49 | $criteria->setSort('art_created'); |
||
| 50 | $criteria->setOrder('DESC'); |
||
| 51 | break; |
||
| 52 | // For the block: articles new |
||
| 53 | case 'new': |
||
| 54 | //$criteria->add(new \Criteria('art_display', 1)); |
||
| 55 | $criteria->add(new \Criteria('art_created', strtotime(date(_SHORTDATESTRING)), '>=')); |
||
| 56 | $criteria->add(new \Criteria('art_created', strtotime(date(_SHORTDATESTRING))+86400, '<=')); |
||
| 57 | $criteria->setSort('art_created'); |
||
| 58 | $criteria->setOrder('ASC'); |
||
| 59 | break; |
||
| 60 | // For the block: articles hits |
||
| 61 | case 'hits': |
||
| 62 | $criteria->setSort('art_hits'); |
||
| 63 | $criteria->setOrder('DESC'); |
||
| 64 | break; |
||
| 65 | // For the block: articles top |
||
| 66 | case 'top': |
||
| 67 | $criteria->setSort('art_top'); |
||
| 68 | $criteria->setOrder('ASC'); |
||
| 69 | break; |
||
| 70 | // For the block: articles random |
||
| 71 | case 'random': |
||
| 72 | //$criteria->add(new \Criteria('art_display', 1)); |
||
| 73 | $criteria->setSort('RAND()'); |
||
| 74 | break; |
||
| 75 | } |
||
| 76 | $criteria->setLimit($limit); |
||
| 77 | $articlesAll = $articlesHandler->getAll($criteria); |
||
| 78 | unset($criteria); |
||
| 79 | if (count($articlesAll) > 0) { |
||
| 80 | foreach(array_keys($articlesAll) as $i) |
||
| 81 | { |
||
| 82 | $block[$i]['cat'] = $articlesAll[$i]->getVar('art_cat'); |
||
| 83 | $block[$i]['title'] = $myts->htmlSpecialChars($articlesAll[$i]->getVar('art_title')); |
||
| 84 | $block[$i]['descr'] = strip_tags($articlesAll[$i]->getVar('art_descr')); |
||
| 85 | $block[$i]['img'] = $articlesAll[$i]->getVar('art_img'); |
||
| 86 | $block[$i]['file'] = $articlesAll[$i]->getVar('art_file'); |
||
| 87 | $block[$i]['created'] = formatTimeStamp($articlesAll[$i]->getVar('art_created')); |
||
| 88 | $block[$i]['submitter'] = \XoopsUser::getUnameFromId($articlesAll[$i]->getVar('art_submitter')); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | return $block; |
||
| 92 | } |
||
| 122 | } |