Conditions | 7 |
Paths | 8 |
Total Lines | 52 |
Code Lines | 40 |
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 |
||
34 | function b_wggithub_repositories_show($options) |
||
35 | { |
||
36 | include_once \XOOPS_ROOT_PATH . '/modules/wggithub/class/repositories.php'; |
||
37 | $myts = MyTextSanitizer::getInstance(); |
||
38 | $GLOBALS['xoopsTpl']->assign('wggithub_upload_url', \WGGITHUB_UPLOAD_URL); |
||
39 | $block = []; |
||
40 | $typeBlock = $options[0]; |
||
41 | $limit = $options[1]; |
||
42 | $lenghtTitle = $options[2]; |
||
43 | $helper = Helper::getInstance(); |
||
44 | $repositoriesHandler = $helper->getHandler('Repositories'); |
||
45 | $crRepositories = 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: repositories last |
||
54 | $crRepositories->setSort('repo_datecreated'); |
||
55 | $crRepositories->setOrder('DESC'); |
||
56 | break; |
||
57 | case 'new': |
||
58 | // For the block: repositories new |
||
59 | $crRepositories->add(new \Criteria('repo_datecreated', \time() - 604800, '>=')); |
||
60 | $crRepositories->add(new \Criteria('repo_datecreated', \time(), '<=')); |
||
61 | $crRepositories->setSort('repo_datecreated'); |
||
62 | $crRepositories->setOrder('ASC'); |
||
63 | break; |
||
64 | case 'random': |
||
65 | // For the block: repositories random |
||
66 | $crRepositories->setSort('RAND()'); |
||
67 | break; |
||
68 | } |
||
69 | |||
70 | $crRepositories->setLimit($limit); |
||
71 | $repositoriesAll = $repositoriesHandler->getAll($crRepositories); |
||
72 | unset($crRepositories); |
||
73 | if (\count($repositoriesAll) > 0) { |
||
74 | foreach (\array_keys($repositoriesAll) as $i) { |
||
75 | $block[$i]['id'] = $repositoriesAll[$i]->getVar('repo_id'); |
||
76 | $repoName = $myts->htmlSpecialChars($repositoriesAll[$i]->getVar('repo_name')); |
||
77 | if ($lenghtTitle > 0) { |
||
78 | $repoName = \substr($repoName, 0, $lenghtTitle); |
||
79 | } |
||
80 | $block[$i]['name'] = $repoName; |
||
81 | $block[$i]['htmlurl'] = $myts->htmlSpecialChars($repositoriesAll[$i]->getVar('repo_htmlurl')); |
||
82 | } |
||
83 | } |
||
84 | |||
85 | return $block; |
||
86 | |||
125 |