| Conditions | 8 |
| Paths | 12 |
| Total Lines | 56 |
| Code Lines | 41 |
| 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_testfields_show($options) |
||
| 30 | { |
||
| 31 | include_once XOOPS_ROOT_PATH.'/modules/mymodule2/class/testfields.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 | $testfieldsHandler = $helper->getHandler('testfields'); |
||
| 40 | $criteria = new \CriteriaCompo(); |
||
| 41 | array_shift($options); |
||
| 42 | array_shift($options); |
||
| 43 | array_shift($options); |
||
| 44 | switch($typeBlock) |
||
| 45 | { |
||
| 46 | // For the block: testfields last |
||
| 47 | case 'last': |
||
| 48 | //$criteria->add(new \Criteria('tf_display', 1)); |
||
| 49 | $criteria->setSort('tf_created'); |
||
| 50 | $criteria->setOrder('DESC'); |
||
| 51 | break; |
||
| 52 | // For the block: testfields new |
||
| 53 | case 'new': |
||
| 54 | //$criteria->add(new \Criteria('tf_display', 1)); |
||
| 55 | $criteria->add(new \Criteria('tf_created', strtotime(date(_SHORTDATESTRING)), '>=')); |
||
| 56 | $criteria->add(new \Criteria('tf_created', strtotime(date(_SHORTDATESTRING))+86400, '<=')); |
||
| 57 | $criteria->setSort('tf_created'); |
||
| 58 | $criteria->setOrder('ASC'); |
||
| 59 | break; |
||
| 60 | // For the block: testfields hits |
||
| 61 | case 'hits': |
||
| 62 | $criteria->setSort('tf_hits'); |
||
| 63 | $criteria->setOrder('DESC'); |
||
| 64 | break; |
||
| 65 | // For the block: testfields top |
||
| 66 | case 'top': |
||
| 67 | $criteria->setSort('tf_top'); |
||
| 68 | $criteria->setOrder('ASC'); |
||
| 69 | break; |
||
| 70 | // For the block: testfields random |
||
| 71 | case 'random': |
||
| 72 | //$criteria->add(new \Criteria('tf_display', 1)); |
||
| 73 | $criteria->setSort('RAND()'); |
||
| 74 | break; |
||
| 75 | } |
||
| 76 | $criteria->setLimit($limit); |
||
| 77 | $testfieldsAll = $testfieldsHandler->getAll($criteria); |
||
| 78 | unset($criteria); |
||
| 79 | if (count($testfieldsAll) > 0) { |
||
| 80 | foreach(array_keys($testfieldsAll) as $i) |
||
| 81 | { |
||
| 82 | } |
||
| 83 | } |
||
| 84 | return $block; |
||
| 85 | } |
||
| 115 | } |