Conditions | 20 |
Paths | > 20000 |
Total Lines | 160 |
Code Lines | 98 |
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 |
||
139 | protected function getList() |
||
140 | { |
||
141 | if (isset($this->request->get['sort'])) { |
||
142 | $sort = $this->request->get['sort']; |
||
143 | } else { |
||
144 | $sort = 'name'; |
||
145 | } |
||
146 | |||
147 | if (isset($this->request->get['order'])) { |
||
148 | $order = $this->request->get['order']; |
||
149 | } else { |
||
150 | $order = 'ASC'; |
||
151 | } |
||
152 | |||
153 | if (isset($this->request->get['page'])) { |
||
154 | $page = $this->request->get['page']; |
||
155 | } else { |
||
156 | $page = 1; |
||
157 | } |
||
158 | |||
159 | $url = ''; |
||
160 | |||
161 | if (isset($this->request->get['sort'])) { |
||
162 | $url .= '&sort=' . $this->request->get['sort']; |
||
163 | } |
||
164 | |||
165 | if (isset($this->request->get['order'])) { |
||
166 | $url .= '&order=' . $this->request->get['order']; |
||
167 | } |
||
168 | |||
169 | if (isset($this->request->get['page'])) { |
||
170 | $url .= '&page=' . $this->request->get['page']; |
||
171 | } |
||
172 | |||
173 | $data['breadcrumbs'] = array(); |
||
174 | |||
175 | $data['breadcrumbs'][] = array( |
||
176 | 'text' => $this->language->get('text_home'), |
||
177 | 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true) |
||
178 | ); |
||
179 | |||
180 | $data['breadcrumbs'][] = array( |
||
181 | 'text' => $this->language->get('heading_title'), |
||
182 | 'href' => $this->url->link('design/sticker', 'token=' . $this->session->data['token'] . $url, true) |
||
183 | ); |
||
184 | |||
185 | $data['add'] = $this->url->link('design/sticker/add', 'token=' . $this->session->data['token'] . $url, true); |
||
186 | $data['delete'] = $this->url->link('design/sticker/delete', 'token=' . $this->session->data['token'] . $url, true); |
||
187 | |||
188 | $data['stickers'] = array(); |
||
189 | |||
190 | $filter_data = array( |
||
191 | 'sort' => $sort, |
||
192 | 'order' => $order, |
||
193 | 'start' => ($page - 1) * $this->config->get('config_limit_admin'), |
||
194 | 'limit' => $this->config->get('config_limit_admin') |
||
195 | ); |
||
196 | |||
197 | $sticker_total = $this->model_design_sticker->getTotalStickers(); |
||
198 | |||
199 | $results = $this->model_design_sticker->getStickers($filter_data); |
||
200 | |||
201 | |||
202 | |||
203 | foreach ($results as $result) { |
||
204 | if ($result['image'] && file_exists($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . $result['image'])) { |
||
205 | $image = '/public_html/assets/images/' . $result['image']; |
||
206 | } else { |
||
207 | $image = '/public_html/assets/images/no_image.png'; |
||
208 | } |
||
209 | |||
210 | $data['stickers'][] = array( |
||
211 | 'sticker_id' => $result['sticker_id'], |
||
212 | 'name' => $result['name'], |
||
213 | 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), |
||
214 | 'edit' => $this->url->link('design/sticker/edit', 'token=' . $this->session->data['token'] . '&sticker_id=' . $result['sticker_id'] . $url, true), |
||
215 | 'image' => $image, |
||
216 | ); |
||
217 | } |
||
218 | |||
219 | $data['heading_title'] = $this->language->get('heading_title'); |
||
220 | |||
221 | $data['text_list'] = $this->language->get('text_list'); |
||
222 | $data['text_no_results'] = $this->language->get('text_no_results'); |
||
223 | $data['text_confirm'] = $this->language->get('text_confirm'); |
||
224 | |||
225 | $data['column_image'] = $this->language->get('column_image'); |
||
226 | $data['column_name'] = $this->language->get('column_name'); |
||
227 | $data['column_status'] = $this->language->get('column_status'); |
||
228 | $data['column_action'] = $this->language->get('column_action'); |
||
229 | |||
230 | $data['button_add'] = $this->language->get('button_add'); |
||
231 | $data['button_edit'] = $this->language->get('button_edit'); |
||
232 | $data['button_delete'] = $this->language->get('button_delete'); |
||
233 | |||
234 | |||
235 | |||
236 | if (isset($this->error['warning'])) { |
||
237 | $data['error_warning'] = $this->error['warning']; |
||
238 | } else { |
||
239 | $data['error_warning'] = ''; |
||
240 | } |
||
241 | |||
242 | if (isset($this->session->data['success'])) { |
||
243 | $data['success'] = $this->session->data['success']; |
||
244 | |||
245 | unset($this->session->data['success']); |
||
246 | } else { |
||
247 | $data['success'] = ''; |
||
248 | } |
||
249 | |||
250 | if (isset($this->request->post['selected'])) { |
||
251 | $data['selected'] = (array)$this->request->post['selected']; |
||
252 | } else { |
||
253 | $data['selected'] = array(); |
||
254 | } |
||
255 | |||
256 | $url = ''; |
||
257 | |||
258 | if ($order == 'ASC') { |
||
259 | $url .= '&order=DESC'; |
||
260 | } else { |
||
261 | $url .= '&order=ASC'; |
||
262 | } |
||
263 | |||
264 | if (isset($this->request->get['page'])) { |
||
265 | $url .= '&page=' . $this->request->get['page']; |
||
266 | } |
||
267 | |||
268 | $data['sort_name'] = $this->url->link('design/sticker', 'token=' . $this->session->data['token'] . '&sort=name' . $url, true); |
||
269 | $data['sort_status'] = $this->url->link('design/sticker', 'token=' . $this->session->data['token'] . '&sort=status' . $url, true); |
||
270 | |||
271 | $url = ''; |
||
272 | |||
273 | if (isset($this->request->get['sort'])) { |
||
274 | $url .= '&sort=' . $this->request->get['sort']; |
||
275 | } |
||
276 | |||
277 | if (isset($this->request->get['order'])) { |
||
278 | $url .= '&order=' . $this->request->get['order']; |
||
279 | } |
||
280 | |||
281 | $pagination = new \Divine\Engine\Library\Pagination(); |
||
282 | $pagination->total = $sticker_total; |
||
283 | $pagination->page = $page; |
||
284 | $pagination->limit = $this->config->get('config_limit_admin'); |
||
285 | $pagination->url = $this->url->link('design/sticker', 'token=' . $this->session->data['token'] . $url . '&page={page}', true); |
||
286 | |||
287 | $data['pagination'] = $pagination->render(); |
||
288 | |||
289 | $data['results'] = sprintf($this->language->get('text_pagination'), ($sticker_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($sticker_total - $this->config->get('config_limit_admin'))) ? $sticker_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $sticker_total, ceil($sticker_total / $this->config->get('config_limit_admin'))); |
||
290 | |||
291 | $data['sort'] = $sort; |
||
292 | $data['order'] = $order; |
||
293 | |||
294 | $data['header'] = $this->load->controller('common/header'); |
||
295 | $data['column'] = $this->load->controller('common/column_left'); |
||
296 | $data['footer'] = $this->load->controller('common/footer'); |
||
297 | |||
298 | $this->response->setOutput($this->load->view('design/sticker_list', $data)); |
||
299 | } |
||
463 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.