| Conditions | 8 |
| Paths | 12 |
| Total Lines | 62 |
| Code Lines | 49 |
| 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_testfields_show($options) |
||
| 35 | { |
||
| 36 | include_once XOOPS_ROOT_PATH . '/modules/mymodule3/class/testfields.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 | $testfieldsHandler = $helper->getHandler('testfields'); |
||
| 45 | $crTestfields = 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: testfields last |
||
| 54 | $crTestfields->add( new \Criteria( 'tf_status', Constants::PERM_GLOBAL_VIEW ) ); |
||
| 55 | $crTestfields->setSort( 'tf_date' ); |
||
| 56 | $crTestfields->setOrder( 'DESC' ); |
||
| 57 | break; |
||
| 58 | case 'new': |
||
| 59 | // For the block: testfields new |
||
| 60 | $crTestfields->add( new \Criteria( 'tf_status', Constants::PERM_GLOBAL_VIEW ) ); |
||
| 61 | $crTestfields->add( new \Criteria( 'tf_date', strtotime(date(_SHORTDATESTRING)), '>=' ) ); |
||
| 62 | $crTestfields->add( new \Criteria( 'tf_date', strtotime(date(_SHORTDATESTRING))+86400, '<=' ) ); |
||
| 63 | $crTestfields->setSort( 'tf_date' ); |
||
| 64 | $crTestfields->setOrder( 'ASC' ); |
||
| 65 | break; |
||
| 66 | case 'hits': |
||
| 67 | // For the block: testfields hits |
||
| 68 | $crTestfields->add( new \Criteria( 'tf_status', Constants::PERM_GLOBAL_VIEW ) ); |
||
| 69 | $crTestfields->setSort( 'tf_hits' ); |
||
| 70 | $crTestfields->setOrder( 'DESC' ); |
||
| 71 | break; |
||
| 72 | case 'top': |
||
| 73 | // For the block: testfields top |
||
| 74 | $crTestfields->add( new \Criteria( 'tf_status', Constants::PERM_GLOBAL_VIEW ) ); |
||
| 75 | $crTestfields->add( new \Criteria( 'tf_date', strtotime(date(_SHORTDATESTRING))+86400, '<=' ) ); |
||
| 76 | $crTestfields->setSort( 'tf_top' ); |
||
| 77 | $crTestfields->setOrder( 'ASC' ); |
||
| 78 | break; |
||
| 79 | case 'random': |
||
| 80 | // For the block: testfields random |
||
| 81 | $crTestfields->add( new \Criteria( 'tf_status', Constants::PERM_GLOBAL_VIEW ) ); |
||
| 82 | $crTestfields->add( new \Criteria( 'tf_date', strtotime(date(_SHORTDATESTRING))+86400, '<=' ) ); |
||
| 83 | $crTestfields->setSort( 'RAND()' ); |
||
| 84 | break; |
||
| 85 | } |
||
| 86 | |||
| 87 | $crTestfields->setLimit( $limit ); |
||
| 88 | $testfieldsAll = $testfieldsHandler->getAll($crTestfields); |
||
| 89 | unset($crTestfields); |
||
| 90 | if (count($testfieldsAll) > 0) { |
||
| 91 | foreach(array_keys($testfieldsAll) as $i) { |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | return $block; |
||
| 96 | |||
| 135 |