| Conditions | 11 |
| Paths | 32 |
| Total Lines | 65 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 23 | function references_search($queryarray, $andor, $limit, $offset, $userid) |
||
| 24 | { |
||
| 25 | global $xoopsDB; |
||
| 26 | include XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
||
| 27 | |||
| 28 | // Recherche dans les articles |
||
| 29 | $sql = 'SELECT article_id, article_title, article_text, article_timestamp, article_author FROM ' . $xoopsDB->prefix('references_articles') . ' WHERE (article_online = ' . REFERENCES_STATUS_ONLINE . ')'; |
||
| 30 | // Permissions |
||
| 31 | $handlers = references_handler::getInstance(); |
||
| 32 | $permissions = $handlers->h_references_articles->getPermissionsCategoriesCriteria()->renderWhere(); |
||
| 33 | $sql .= ' AND (' . trim(str_replace('WHERE ', '', $permissions)) . ')'; |
||
| 34 | // ***** |
||
| 35 | |||
| 36 | // Auteur |
||
| 37 | if ($userid != 0) { |
||
| 38 | $sql .= ' AND (article_author = ' . $userid . ') '; |
||
| 39 | } |
||
| 40 | |||
| 41 | $tmpObject = new references_articles(); |
||
| 42 | $datas = $tmpObject->getVars(); |
||
| 43 | $tblFields = array(); |
||
| 44 | $cnt = 0; |
||
| 45 | foreach ($datas as $key => $value) { |
||
| 46 | if ($value['data_type'] == XOBJ_DTYPE_TXTBOX || $value['data_type'] == XOBJ_DTYPE_TXTAREA) { |
||
| 47 | if ($cnt == 0) { |
||
| 48 | $tblFields[] = $key; |
||
| 49 | } else { |
||
| 50 | $tblFields[] = ' OR ' . $key; |
||
| 51 | } |
||
| 52 | ++$cnt; |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | $count = count($queryarray); |
||
| 57 | $more = ''; |
||
| 58 | if (is_array($queryarray) && $count > 0) { |
||
| 59 | $cnt = 0; |
||
| 60 | $sql .= ' AND ('; |
||
| 61 | $more = ')'; |
||
| 62 | foreach ($queryarray as $oneQuery) { |
||
| 63 | $sql .= '('; |
||
| 64 | $cond = " LIKE '%" . $oneQuery . "%' "; |
||
| 65 | $sql .= implode($cond, $tblFields) . $cond . ')'; |
||
| 66 | ++$cnt; |
||
| 67 | if ($cnt != $count) { |
||
| 68 | $sql .= ' ' . $andor . ' '; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |
||
| 72 | $sql .= $more . ' ORDER BY article_timestamp DESC'; |
||
| 73 | $i = 0; |
||
| 74 | $ret = array(); |
||
| 75 | $myts = MyTextSanitizer::getInstance(); |
||
| 76 | $result = $xoopsDB->query($sql, $limit, $offset); |
||
| 77 | while ($myrow = $xoopsDB->fetchArray($result)) { |
||
| 78 | $ret[$i]['image'] = 'assets/images/newspaper.png'; |
||
| 79 | $ret[$i]['link'] = REFERENCES_URL . 'reference.php?article_id=' . $myrow['article_id']; |
||
| 80 | $ret[$i]['title'] = $myts->htmlSpecialChars($myrow['article_title']); |
||
| 81 | $ret[$i]['time'] = $myrow['article_timestamp']; |
||
| 82 | $ret[$i]['uid'] = $myrow['article_author']; |
||
| 83 | ++$i; |
||
| 84 | } |
||
| 85 | |||
| 86 | return $ret; |
||
| 87 | } |
||
| 88 |