| Conditions | 33 |
| Paths | > 20000 |
| Total Lines | 130 |
| Code Lines | 95 |
| 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 |
||
| 30 | function publisher_search_show($options) |
||
|
|
|||
| 31 | { |
||
| 32 | $block = []; |
||
| 33 | $xoops = Xoops::getInstance(); |
||
| 34 | $helper = Helper::getInstance(); |
||
| 35 | $categories = $helper->getCategoryHandler()->getCategoriesForSearch(); |
||
| 36 | if (0 == count($categories)) { |
||
| 37 | return $block; |
||
| 38 | } |
||
| 39 | |||
| 40 | $andor = $_POST['andor'] ?? (isset($_GET['andor']) ? $_GET['andor'] : ''); |
||
| 41 | |||
| 42 | $category = $_POST['category'] ?? (isset($_GET['category']) ? $_GET['category'] : null); |
||
| 43 | $username = $_POST['uname'] ?? (isset($_GET['uname']) ? $_GET['uname'] : null); |
||
| 44 | $searchin = $_POST['searchin'] ?? (isset($_GET['searchin']) ? explode('|', $_GET['searchin']) : []); |
||
| 45 | $sortby = $_POST['sortby'] ?? (isset($_GET['sortby']) ? $_GET['sortby'] : null); |
||
| 46 | $term = $_POST['term'] ?? (isset($_GET['term']) ? $_GET['term'] : ''); |
||
| 47 | |||
| 48 | if (empty($category) || (is_array($category) && in_array('all', $category))) { |
||
| 49 | $category = []; |
||
| 50 | } else { |
||
| 51 | $category = (!is_array($category)) ? explode(',', $category) : $category; |
||
| 52 | $category = array_map('\intval', $category); |
||
| 53 | } |
||
| 54 | |||
| 55 | $andor = in_array(mb_strtoupper($andor), ['OR', 'AND', 'EXACT']) ? mb_strtoupper($andor) : 'OR'; |
||
| 56 | $sortby = in_array(mb_strtolower($sortby), ['itemid', 'datesub', 'title', 'categoryid']) ? mb_strtolower($sortby) : 'itemid'; |
||
| 57 | |||
| 58 | /* type */ |
||
| 59 | $type_select = '<select name="andor">'; |
||
| 60 | $type_select .= '<option value="OR"'; |
||
| 61 | if ('OR' === $andor) { |
||
| 62 | $type_select .= ' selected="selected"'; |
||
| 63 | } |
||
| 64 | $type_select .= '>' . XoopsLocale::ANY_OR . '</option>'; |
||
| 65 | $type_select .= '<option value="AND"'; |
||
| 66 | if ('AND' === $andor) { |
||
| 67 | $type_select .= ' selected="selected"'; |
||
| 68 | } |
||
| 69 | $type_select .= '>' . XoopsLocale::ALL . '</option>'; |
||
| 70 | $type_select .= '<option value="EXACT"'; |
||
| 71 | if ('exact' === $andor) { |
||
| 72 | $type_select .= ' selected="selected"'; |
||
| 73 | } |
||
| 74 | $type_select .= '>' . XoopsLocale::EXACT_MATCH . '</option>'; |
||
| 75 | $type_select .= '</select>'; |
||
| 76 | |||
| 77 | /* category */ |
||
| 78 | |||
| 79 | $select_category = '<select name="category[]" size="5" multiple="multiple" width="150" style="width:150px;">'; |
||
| 80 | $select_category .= '<option value="all"'; |
||
| 81 | if (empty($category) || 0 == count($category)) { |
||
| 82 | $select_category .= 'selected="selected"'; |
||
| 83 | } |
||
| 84 | $select_category .= '>' . XoopsLocale::ALL . '</option>'; |
||
| 85 | foreach ($categories as $id => $cat) { |
||
| 86 | $select_category .= '<option value="' . $id . '"'; |
||
| 87 | if (in_array($id, $category)) { |
||
| 88 | $select_category .= 'selected="selected"'; |
||
| 89 | } |
||
| 90 | $select_category .= '>' . $cat . '</option>'; |
||
| 91 | } |
||
| 92 | $select_category .= '</select>'; |
||
| 93 | |||
| 94 | /* scope */ |
||
| 95 | $searchin_select = ''; |
||
| 96 | $searchin_select .= '<input type="checkbox" name="searchin[]" value="title"'; |
||
| 97 | if (in_array('title', $searchin)) { |
||
| 98 | $searchin_select .= ' checked'; |
||
| 99 | } |
||
| 100 | $searchin_select .= '>' . _CO_PUBLISHER_TITLE . ' '; |
||
| 101 | $searchin_select .= '<input type="checkbox" name="searchin[]" value="subtitle"'; |
||
| 102 | if (in_array('subtitle', $searchin)) { |
||
| 103 | $searchin_select .= ' checked'; |
||
| 104 | } |
||
| 105 | $searchin_select .= '>' . _CO_PUBLISHER_SUBTITLE . ' '; |
||
| 106 | $searchin_select .= '<input type="checkbox" name="searchin[]" value="summary"'; |
||
| 107 | if (in_array('summary', $searchin)) { |
||
| 108 | $searchin_select .= ' checked'; |
||
| 109 | } |
||
| 110 | $searchin_select .= '>' . _CO_PUBLISHER_SUMMARY . ' '; |
||
| 111 | $searchin_select .= '<input type="checkbox" name="searchin[]" value="text"'; |
||
| 112 | if (in_array('body', $searchin)) { |
||
| 113 | $searchin_select .= ' checked'; |
||
| 114 | } |
||
| 115 | $searchin_select .= '>' . _CO_PUBLISHER_BODY . ' '; |
||
| 116 | $searchin_select .= '<input type="checkbox" name="searchin[]" value="keywords"'; |
||
| 117 | if (in_array('meta_keywords', $searchin)) { |
||
| 118 | $searchin_select .= ' checked'; |
||
| 119 | } |
||
| 120 | $searchin_select .= '>' . _CO_PUBLISHER_ITEM_META_KEYWORDS . ' '; |
||
| 121 | $searchin_select .= '<input type="checkbox" name="searchin[]" value="all"'; |
||
| 122 | if (in_array('all', $searchin) || empty($searchin)) { |
||
| 123 | $searchin_select .= ' checked'; |
||
| 124 | } |
||
| 125 | $searchin_select .= '>' . XoopsLocale::ALL . ' '; |
||
| 126 | |||
| 127 | /* sortby */ |
||
| 128 | $sortby_select = '<select name="sortby">'; |
||
| 129 | $sortby_select .= '<option value="itemid"'; |
||
| 130 | if ('itemid' === $sortby || empty($sortby)) { |
||
| 131 | $sortby_select .= ' selected="selected"'; |
||
| 132 | } |
||
| 133 | $sortby_select .= '>' . XoopsLocale::NONE . '</option>'; |
||
| 134 | $sortby_select .= '<option value="datesub"'; |
||
| 135 | if ('datesub' === $sortby) { |
||
| 136 | $sortby_select .= ' selected="selected"'; |
||
| 137 | } |
||
| 138 | $sortby_select .= '>' . _CO_PUBLISHER_DATESUB . '</option>'; |
||
| 139 | $sortby_select .= '<option value="title"'; |
||
| 140 | if ('title' === $sortby) { |
||
| 141 | $sortby_select .= ' selected="selected"'; |
||
| 142 | } |
||
| 143 | $sortby_select .= '>' . _CO_PUBLISHER_TITLE . '</option>'; |
||
| 144 | $sortby_select .= '<option value="categoryid"'; |
||
| 145 | if ('categoryid' === $sortby) { |
||
| 146 | $sortby_select .= ' selected="selected"'; |
||
| 147 | } |
||
| 148 | $sortby_select .= '>' . _CO_PUBLISHER_CATEGORY . '</option>'; |
||
| 149 | $sortby_select .= '</select>'; |
||
| 150 | |||
| 151 | $block['type_select'] = $type_select; |
||
| 152 | $block['searchin_select'] = $searchin_select; |
||
| 153 | $block['category_select'] = $select_category; |
||
| 154 | $block['sortby_select'] = $sortby_select; |
||
| 155 | $block['search_term'] = $term; |
||
| 156 | $block['search_user'] = $username; |
||
| 157 | $block['publisher_url'] = PUBLISHER_URL; |
||
| 158 | |||
| 159 | return $block; |
||
| 160 | } |
||
| 161 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.