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