| Conditions | 12 |
| Paths | 192 |
| Total Lines | 58 |
| 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 |
||
| 36 | function wggithub_search($queryarray, $andor, $limit, $offset, $userid) |
||
|
|
|||
| 37 | {
|
||
| 38 | $ret = []; |
||
| 39 | $helper = \XoopsModules\Wggithub\Helper::getInstance(); |
||
| 40 | $repositoriesHandler = $helper->getHandler('Repositories');
|
||
| 41 | $directoriesHandler = $helper->getHandler('Directories');
|
||
| 42 | |||
| 43 | $directoriesAll = $directoriesHandler->getAll(); |
||
| 44 | foreach (\array_keys($directoriesAll) as $i) {
|
||
| 45 | $directories[$directoriesAll[$i]->getVar('dir_name')] = $directoriesAll[$i]->getVar('dir_id');
|
||
| 46 | } |
||
| 47 | unset ($directoriesAll); |
||
| 48 | |||
| 49 | // search in table repositories |
||
| 50 | // search keywords |
||
| 51 | $elementCount = 0; |
||
| 52 | if (\is_array($queryarray)) {
|
||
| 53 | $elementCount = \count($queryarray); |
||
| 54 | } |
||
| 55 | if ($elementCount > 0) {
|
||
| 56 | $crKeywords = new \CriteriaCompo(); |
||
| 57 | for ($i = 0; $i < $elementCount; $i++) {
|
||
| 58 | $crKeyword = new \CriteriaCompo(); |
||
| 59 | unset($crKeyword); |
||
| 60 | } |
||
| 61 | } |
||
| 62 | // search user(s) |
||
| 63 | if ($userid && \is_array($userid)) {
|
||
| 64 | $userid = array_map('intval', $userid);
|
||
| 65 | $crUser = new \CriteriaCompo(); |
||
| 66 | $crUser->add(new \Criteria('repo_submitter', '(' . \implode(',', $userid) . ')', 'IN'), 'OR');
|
||
| 67 | } elseif (is_numeric($userid) && $userid > 0) {
|
||
| 68 | $crUser = new \CriteriaCompo(); |
||
| 69 | $crUser->add(new \Criteria('repo_submitter', $userid), 'OR');
|
||
| 70 | } |
||
| 71 | $crSearch = new \CriteriaCompo(); |
||
| 72 | if (isset($crKeywords)) {
|
||
| 73 | $crSearch->add($crKeywords, 'AND'); |
||
| 74 | } |
||
| 75 | if (isset($crUser)) {
|
||
| 76 | $crSearch->add($crUser, 'AND'); |
||
| 77 | } |
||
| 78 | $crSearch->setStart($offset); |
||
| 79 | $crSearch->setLimit($limit); |
||
| 80 | $crSearch->setSort('repo_datecreated');
|
||
| 81 | $crSearch->setOrder('DESC');
|
||
| 82 | $repositoriesAll = $repositoriesHandler->getAll($crSearch); |
||
| 83 | foreach (\array_keys($repositoriesAll) as $i) {
|
||
| 84 | $ret[] = [ |
||
| 85 | 'image' => 'assets/icons/16/github.png', |
||
| 86 | 'link' => 'index.php?op=show&menu=' . $directories[$repositoriesAll[$i]->getVar('repo_user')],
|
||
| 87 | 'title' => $repositoriesAll[$i]->getVar('repo_name'),
|
||
| 88 | 'time' => $repositoriesAll[$i]->getVar('repo_datecreated')
|
||
| 89 | ]; |
||
| 90 | } |
||
| 91 | unset($crKeywords, $crKeyword, $crUser, $crSearch, $repositoriesAll); |
||
| 92 | |||
| 93 | return $ret; |
||
| 94 | |||
| 96 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.