| Conditions | 5 |
| Paths | 6 |
| Total Lines | 52 |
| Code Lines | 30 |
| 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 |
||
| 35 | function b_wgfilemanager_directory_show($options) |
||
| 36 | { |
||
| 37 | $block = []; |
||
| 38 | $typeBlock = $options[0]; |
||
| 39 | $limit = $options[1]; |
||
| 40 | //$lenghtTitle = $options[2]; |
||
| 41 | $helper = Helper::getInstance(); |
||
| 42 | $directoryHandler = $helper->getHandler('Directory'); |
||
| 43 | $crDirectory = new \CriteriaCompo(); |
||
| 44 | \array_shift($options); |
||
| 45 | \array_shift($options); |
||
| 46 | \array_shift($options); |
||
| 47 | |||
| 48 | switch ($typeBlock) { |
||
| 49 | case 'last': |
||
| 50 | default: |
||
| 51 | // For the block: directory last |
||
| 52 | $crDirectory->setSort('date_created'); |
||
| 53 | $crDirectory->setOrder('DESC'); |
||
| 54 | break; |
||
| 55 | case 'new': |
||
| 56 | // For the block: directory new |
||
| 57 | // new since last week: 7 * 24 * 60 * 60 = 604800 |
||
| 58 | $crDirectory->add(new \Criteria('date_created', \time() - 604800, '>=')); |
||
| 59 | $crDirectory->add(new \Criteria('date_created', \time(), '<=')); |
||
| 60 | $crDirectory->setSort('date_created'); |
||
| 61 | $crDirectory->setOrder('ASC'); |
||
| 62 | break; |
||
| 63 | } |
||
| 64 | |||
| 65 | $crDirectory->setLimit($limit); |
||
| 66 | $directoryAll = $directoryHandler->getAll($crDirectory); |
||
| 67 | unset($crDirectory); |
||
| 68 | if (\count($directoryAll) > 0) { |
||
| 69 | foreach (\array_keys($directoryAll) as $i) { |
||
| 70 | /** |
||
| 71 | * If you want to use the parameter for limits you have to adapt the line where it should be applied |
||
| 72 | * e.g. change |
||
| 73 | * $block[$i]['title'] = $directoryAll[$i]->getVar('art_title'); |
||
| 74 | * into |
||
| 75 | * $myTitle = $directoryAll[$i]->getVar('art_title'); |
||
| 76 | * if ($limit > 0) { |
||
| 77 | * $myTitle = \substr($myTitle, 0, (int)$limit); |
||
| 78 | * } |
||
| 79 | * $block[$i]['title'] = $myTitle; |
||
| 80 | */ |
||
| 81 | $block[$i]['id'] = $directoryAll[$i]->getVar('id'); |
||
| 82 | $block[$i]['name'] = \htmlspecialchars($directoryAll[$i]->getVar('name'), ENT_QUOTES | ENT_HTML5); |
||
| 83 | } |
||
| 84 | } |
||
| 85 | $GLOBALS['xoopsTpl']->assign('wgfilemanager_url', \WGFILEMANAGER_URL); |
||
| 86 | return $block; |
||
| 87 | |||
| 132 |