| Conditions | 18 |
| Paths | 56 |
| Total Lines | 83 |
| Code Lines | 61 |
| 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 |
||
| 17 | function sb_search($queryarray, $andor, $limit, $offset, $userid) |
||
| 18 | { |
||
| 19 | global $xoopsUser; |
||
| 20 | $ret = []; |
||
| 21 | if (!is_object($xoopsUser) || 0 === $xoopsUser->getVar('uid')) { |
||
| 22 | return $ret; |
||
| 23 | } |
||
| 24 | $count = count($queryarray); |
||
| 25 | if (0 === $userid) { |
||
| 26 | if (!is_array($queryarray) || empty($queryarray) || 0 === $count) { |
||
| 27 | return $ret; |
||
| 28 | } |
||
| 29 | } |
||
| 30 | //------------------------------------- |
||
| 31 | /** @var \XoopsModules\Soapbox\EntrygetHandler $entrydataHandler */ |
||
| 32 | $entrydataHandler = new \XoopsModules\Soapbox\EntrygetHandler(); |
||
| 33 | //------------------------------------- |
||
| 34 | $canread_columnIDs = []; |
||
| 35 | $canread_columnnames = []; |
||
| 36 | $_userinfo_authors_column = []; |
||
| 37 | $_column_authors_uid = []; |
||
| 38 | //get category object |
||
| 39 | $categoryobArray = $entrydataHandler->getColumnsAllPermcheck(0, 0, true, null, null, null, null, false); |
||
| 40 | foreach ($categoryobArray as $k => $_categoryob) { |
||
| 41 | $canread_columnIDs[] = $_categoryob->getVar('columnID'); |
||
| 42 | $canread_columnnames[$_categoryob->getVar('columnID')] = $_categoryob->getVar('name'); |
||
| 43 | $_column_authors_uid[$_categoryob->getVar('columnID')] = $_categoryob->getVar('author'); |
||
| 44 | if (0 !== $userid && $userid === $_categoryob->getVar('author')) { |
||
| 45 | $_userinfo_authors_column[] = $_categoryob->getVar('columnID'); |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | if (empty($canread_columnIDs)) { |
||
| 50 | return $ret; |
||
| 51 | } |
||
| 52 | $criteria = new \CriteriaCompo(); |
||
| 53 | $crit_canread = new \CriteriaCompo(); |
||
| 54 | $crit_canread->add(new \Criteria('columnID', '(' . implode(',', array_unique($canread_columnIDs)) . ')', 'IN')); |
||
| 55 | $criteria->add($crit_canread, 'AND'); |
||
| 56 | unset($crit_canread); |
||
| 57 | //for userinfo |
||
| 58 | if (0 !== $userid && !empty($_userinfo_authors_column) && count($_userinfo_authors_column) > 0) { |
||
| 59 | $criteria_userinfo = new \CriteriaCompo(); |
||
| 60 | $criteria_userinfo->add(new \Criteria('columnID', '(' . implode(',', array_unique($_userinfo_authors_column)) . ')', 'IN')); |
||
| 61 | $criteria->add($criteria_userinfo, 'AND'); |
||
| 62 | unset($criteria_userinfo); |
||
| 63 | } |
||
| 64 | //for serch form |
||
| 65 | if (is_array($queryarray) && $count > 0) { |
||
| 66 | $crit_query = new \CriteriaCompo(); |
||
| 67 | foreach ($queryarray as $query_v) { |
||
| 68 | $crit_query_one = new \CriteriaCompo(); |
||
| 69 | $crit_query_one->add(new \Criteria('columnID', '(' . implode(',', array_unique($_userinfo_authors_column)) . ')', 'IN')); |
||
| 70 | $crit_query_one->add(new \Criteria('headline', '%' . $query_v . '%', 'like')); |
||
| 71 | $crit_query_one->add(new \Criteria('headline', '.*(' . preg_quote($query_v) . ').*', 'regexp'), 'OR'); |
||
| 72 | $crit_query_one->add(new \Criteria('lead', '%' . $query_v . '%', 'like'), 'OR'); |
||
| 73 | $crit_query_one->add(new \Criteria('lead', '.*(' . preg_quote($query_v) . ').*', 'regexp'), 'OR'); |
||
| 74 | $crit_query_one->add(new \Criteria('bodytext', '%' . $query_v . '%', 'like'), 'OR'); |
||
| 75 | $crit_query_one->add(new \Criteria('bodytext', '.*(' . preg_quote($query_v) . ').*', 'regexp'), 'OR'); |
||
| 76 | $crit_query->add($crit_query_one, $andor); |
||
| 77 | unset($crit_query_one); |
||
| 78 | } |
||
| 79 | $criteria->add($crit_query, 'AND'); |
||
| 80 | } |
||
| 81 | |||
| 82 | $criteria->setStart($offset); |
||
| 83 | $criteria->setLimit($limit); |
||
| 84 | $criteria->setSort('datesub'); |
||
| 85 | $criteria->setOrder('DESC'); |
||
| 86 | $sbarticles_arr = $entrydataHandler->getArticles($criteria); |
||
| 87 | unset($criteria); |
||
| 88 | |||
| 89 | $i = 0; |
||
| 90 | foreach ($sbarticles_arr as $sbarticles) { |
||
| 91 | $ret[$i]['image'] = 'assets/images/sb.png'; |
||
| 92 | $ret[$i]['link'] = 'article.php?articleID=' . $sbarticles->getVar('articleID'); |
||
| 93 | $ret[$i]['title'] = $sbarticles->getVar('headline'); |
||
| 94 | $ret[$i]['time'] = $sbarticles->getVar('datesub'); |
||
| 95 | $ret[$i]['uid'] = $_column_authors_uid[$sbarticles->getVar('columnID')]; |
||
| 96 | ++$i; |
||
| 97 | } |
||
| 98 | |||
| 99 | return $ret; |
||
| 100 | } |
||
| 101 |