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