| Conditions | 5 |
| Paths | 5 |
| Total Lines | 73 |
| Code Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 177 | public function ajax_list_cat() |
||
| 178 | { |
||
| 179 | $i = $j = $cat = 0; |
||
| 180 | $lang_cat = $list_cat = []; |
||
| 181 | $id = (int) $this->request->variable('id', 0); |
||
| 182 | $action = (string) $this->request->variable('action', ''); |
||
| 183 | |||
| 184 | $this->category->move_cat($id, $action); |
||
| 185 | $max = $this->category->get_max_order(); |
||
| 186 | $langs = $this->category->get_langs(); |
||
| 187 | $total = $this->category->category_exist(); |
||
| 188 | |||
| 189 | $sql = $this->db->sql_build_query('SELECT', [ |
||
| 190 | 'SELECT' => 'l.lang_id, l.lang_iso, l.lang_local_name, c.*', |
||
| 191 | 'FROM' => [LANG_TABLE => 'l'], |
||
| 192 | 'LEFT_JOIN' => [ |
||
| 193 | [ |
||
| 194 | 'FROM' => [$this->smilies_category_table => 'c'], |
||
| 195 | 'ON' => 'c.cat_lang = l.lang_iso', |
||
| 196 | ], |
||
| 197 | ], |
||
| 198 | 'ORDER_BY' => 'c.cat_order ASC, c.cat_lang_id ASC', |
||
| 199 | ]); |
||
| 200 | $result = $this->db->sql_query($sql); |
||
| 201 | while ($row = $this->db->sql_fetchrow($result)) |
||
| 202 | { |
||
| 203 | $title = ''; |
||
| 204 | if ((int) $row['cat_id'] !== $cat) |
||
| 205 | { |
||
| 206 | $return = $this->category->verify_cat_langs($langs, $cat, $i, $lang_cat, true); |
||
| 207 | $list_cat[$j] = [ |
||
| 208 | 'error' => $return['error'], |
||
| 209 | 'langEmpty' => $return['lang_empty'], |
||
| 210 | ]; |
||
| 211 | $j++; |
||
| 212 | $title = $this->language->lang('SC_CATEGORY_IN', $this->category->cat_name($row['cat_id'])); |
||
| 213 | } |
||
| 214 | $lang_cat[$row['cat_id']][$row['lang_id']] = $row['lang_iso']; |
||
| 215 | $list_cat[$j] = [ |
||
| 216 | 'titleCat' => $title, |
||
| 217 | 'catLang' => $row['lang_local_name'], |
||
| 218 | 'catIso' => $row['lang_iso'], |
||
| 219 | 'catTranslate' => $row['cat_name'], |
||
| 220 | 'catId' => (int) $row['cat_id'], |
||
| 221 | 'catOrder' => (int) $row['cat_order'], |
||
| 222 | 'catNb' => (int) $row['cat_nb'], |
||
| 223 | 'row' => (int) $row['cat_id'] !== $cat, |
||
| 224 | 'rowMax' => (int) $row['cat_order'] === $max, |
||
| 225 | 'uEdit' => '&action=edit&id=' . $row['cat_id'], |
||
| 226 | 'uDelete' => '&action=delete&id=' . $row['cat_id'], |
||
| 227 | ]; |
||
| 228 | $i++; |
||
| 229 | $j++; |
||
| 230 | // Keep this value in memory |
||
| 231 | $cat = (int) $row['cat_id']; |
||
| 232 | |||
| 233 | // Do this only for the last category |
||
| 234 | if ((int) $row['cat_order'] === $max && ($i === $total)) |
||
| 235 | { |
||
| 236 | $return = $this->category->verify_cat_langs($langs, $cat, $i, $lang_cat, true); |
||
| 237 | $list_cat[$j] = [ |
||
| 238 | 'error' => $return['error'], |
||
| 239 | 'langEmpty' => $return['lang_empty'], |
||
| 240 | ]; |
||
| 241 | $j++; |
||
| 242 | } |
||
| 243 | } |
||
| 244 | $this->db->sql_freeresult($result); |
||
| 245 | |||
| 246 | $json_response = new \phpbb\json_response; |
||
| 247 | $json_response->send([ |
||
| 248 | 'total' => $j, |
||
| 249 | 'datas' => $list_cat, |
||
| 250 | ]); |
||
| 253 |