| Conditions | 21 |
| Paths | > 20000 |
| Total Lines | 259 |
| Code Lines | 163 |
| 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 |
||
| 25 | public function index() |
||
| 26 | { |
||
| 27 | $this->document->addStyle('/public_html/assets/css/application/page/blog/latest.css'); |
||
| 28 | |||
| 29 | $this->load->language('blog/latest'); |
||
| 30 | |||
| 31 | $this->load->model('blog/article'); |
||
| 32 | |||
| 33 | if (isset($this->request->get['sort'])) { |
||
| 34 | $sort = $this->request->get['sort']; |
||
| 35 | $this->document->setRobots('noindex,follow'); |
||
| 36 | } else { |
||
| 37 | $sort = 'p.date_added'; |
||
| 38 | } |
||
| 39 | |||
| 40 | if (isset($this->request->get['order'])) { |
||
| 41 | $order = $this->request->get['order']; |
||
| 42 | } else { |
||
| 43 | $order = 'DESC'; |
||
| 44 | } |
||
| 45 | |||
| 46 | if (isset($this->request->get['page'])) { |
||
| 47 | $page = $this->request->get['page']; |
||
| 48 | $this->document->setRobots('noindex,follow'); |
||
| 49 | } else { |
||
| 50 | $page = 1; |
||
| 51 | } |
||
| 52 | |||
| 53 | if (isset($this->request->get['limit'])) { |
||
| 54 | $limit = $this->request->get['limit']; |
||
| 55 | $this->document->setRobots('noindex,follow'); |
||
| 56 | } else { |
||
| 57 | $limit = $this->config->get('configblog_article_limit'); |
||
| 58 | } |
||
| 59 | |||
| 60 | $configblog_html_h1 = $this->config->get('configblog_html_h1'); |
||
| 61 | |||
| 62 | if (!empty($configblog_html_h1)) { |
||
| 63 | $data['heading_title'] = $this->config->get('configblog_html_h1'); |
||
| 64 | } else { |
||
| 65 | $data['heading_title'] = $this->language->get('heading_title'); |
||
| 66 | } |
||
| 67 | |||
| 68 | $configblog_meta_title = $this->config->get('configblog_meta_title'); |
||
| 69 | |||
| 70 | if (!empty($configblog_meta_title)) { |
||
| 71 | $this->document->setTitle($this->config->get('configblog_meta_title')); |
||
| 72 | } else { |
||
| 73 | $this->document->setTitle($this->language->get('heading_title')); |
||
| 74 | } |
||
| 75 | |||
| 76 | $this->document->setDescription($this->config->get('configblog_meta_description')); |
||
| 77 | |||
| 78 | $data['breadcrumbs'] = array(); |
||
| 79 | |||
| 80 | $data['breadcrumbs'][] = array( |
||
| 81 | 'text' => $this->language->get('text_home'), |
||
| 82 | 'href' => $this->url->link('common/home') |
||
| 83 | ); |
||
| 84 | |||
| 85 | $configblog_name = $this->config->get('configblog_name'); |
||
| 86 | |||
| 87 | if (!empty($configblog_name)) { |
||
| 88 | $name = $this->config->get('configblog_name'); |
||
| 89 | } else { |
||
| 90 | $name = $this->language->get('heading_title'); |
||
| 91 | } |
||
| 92 | |||
| 93 | $data['breadcrumbs'][] = array( |
||
| 94 | 'text' => $name, |
||
| 95 | 'href' => $this->url->link('blog/latest') |
||
| 96 | ); |
||
| 97 | |||
| 98 | $url = ''; |
||
| 99 | |||
| 100 | if (isset($this->request->get['sort'])) { |
||
| 101 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 102 | } |
||
| 103 | |||
| 104 | if (isset($this->request->get['order'])) { |
||
| 105 | $url .= '&order=' . $this->request->get['order']; |
||
| 106 | } |
||
| 107 | |||
| 108 | if (isset($this->request->get['page'])) { |
||
| 109 | $url .= '&page=' . $this->request->get['page']; |
||
| 110 | } |
||
| 111 | |||
| 112 | if (isset($this->request->get['limit'])) { |
||
| 113 | $url .= '&limit=' . $this->request->get['limit']; |
||
| 114 | } |
||
| 115 | |||
| 116 | $data['text_refine'] = $this->language->get('text_refine'); |
||
| 117 | $data['text_views'] = $this->language->get('text_views'); |
||
| 118 | $data['text_empty'] = $this->language->get('text_empty'); |
||
| 119 | $data['text_display'] = $this->language->get('text_display'); |
||
| 120 | $data['text_list'] = $this->language->get('text_list'); |
||
| 121 | $data['text_grid'] = $this->language->get('text_grid'); |
||
| 122 | $data['text_sort'] = $this->language->get('text_sort'); |
||
| 123 | $data['text_limit'] = $this->language->get('text_limit'); |
||
| 124 | |||
| 125 | $data['text_sort_by'] = $this->language->get('text_sort_by'); |
||
| 126 | $data['text_sort_name'] = $this->language->get('text_sort_name'); |
||
| 127 | $data['text_sort_date'] = $this->language->get('text_sort_date'); |
||
| 128 | $data['text_sort_rated'] = $this->language->get('text_sort_rated'); |
||
| 129 | $data['text_sort_viewed'] = $this->language->get('text_sort_viewed'); |
||
| 130 | |||
| 131 | $data['text_go_back'] = $this->language->get('text_go_back'); |
||
| 132 | |||
| 133 | $data['button_more'] = $this->language->get('button_more'); |
||
| 134 | $data['button_continue'] = $this->language->get('button_continue'); |
||
| 135 | |||
| 136 | $data['configblog_review_status'] = $this->config->get('configblog_review_status'); |
||
| 137 | |||
| 138 | $data['articles'] = array(); |
||
| 139 | |||
| 140 | $article_data = array( |
||
| 141 | 'sort' => $sort, |
||
| 142 | 'order' => $order, |
||
| 143 | 'start' => ($page - 1) * $limit, |
||
| 144 | 'limit' => $limit |
||
| 145 | ); |
||
| 146 | |||
| 147 | $article_total = $this->model_blog_article->getTotalArticles($article_data); |
||
| 148 | |||
| 149 | $results = $this->model_blog_article->getArticles($article_data); |
||
| 150 | |||
| 151 | |||
| 152 | foreach ($results as $result) { |
||
| 153 | if ($result['image']) { |
||
| 154 | $image = '/public_html/assets/images/' . $result['image']; |
||
| 155 | } else { |
||
| 156 | $image = '/public_html/assets/images/no_image.png'; |
||
| 157 | } |
||
| 158 | |||
| 159 | $data['articles'][] = array( |
||
| 160 | 'article_id' => $result['article_id'], |
||
| 161 | 'thumb' => $image, |
||
| 162 | 'name' => $result['name'], |
||
| 163 | 'description' => \voku\helper\UTF8::substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('configblog_article_description_length')) . '..', |
||
| 164 | 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), |
||
| 165 | 'viewed' => $result['viewed'], |
||
| 166 | 'reviews' => sprintf($this->language->get('text_reviews'), (int) $result['reviews']), |
||
| 167 | 'href' => $this->url->link('blog/article', '&article_id=' . $result['article_id']) |
||
| 168 | ); |
||
| 169 | } |
||
| 170 | |||
| 171 | $url = ''; |
||
| 172 | |||
| 173 | if (isset($this->request->get['limit'])) { |
||
| 174 | $url .= '&limit=' . $this->request->get['limit']; |
||
| 175 | } |
||
| 176 | |||
| 177 | $data['sorts'] = array(); |
||
| 178 | |||
| 179 | $data['sorts'][] = array( |
||
| 180 | 'text' => $this->language->get('text_default'), |
||
| 181 | 'value' => 'p.sort_order-ASC', |
||
| 182 | 'href' => $this->url->link('blog/latest', 'blog_category_id=' . '&sort=p.sort_order&order=ASC' . $url) |
||
| 183 | ); |
||
| 184 | |||
| 185 | $data['sorts'][] = array( |
||
| 186 | 'text' => $this->language->get('text_name_asc'), |
||
| 187 | 'value' => 'pd.name-ASC', |
||
| 188 | 'href' => $this->url->link('blog/latest', 'blog_category_id=' . '&sort=pd.name&order=ASC' . $url) |
||
| 189 | ); |
||
| 190 | |||
| 191 | $data['sorts'][] = array( |
||
| 192 | 'text' => $this->language->get('text_name_desc'), |
||
| 193 | 'value' => 'pd.name-DESC', |
||
| 194 | 'href' => $this->url->link('blog/latest', 'blog_category_id=' . '&sort=pd.name&order=DESC' . $url) |
||
| 195 | ); |
||
| 196 | |||
| 197 | $data['sorts'][] = array( |
||
| 198 | 'text' => $this->language->get('text_date_asc'), |
||
| 199 | 'value' => 'p.date_added-ASC', |
||
| 200 | 'href' => $this->url->link('blog/latest', '&sort=p.date_added&order=ASC' . $url) |
||
| 201 | ); |
||
| 202 | |||
| 203 | $data['sorts'][] = array( |
||
| 204 | 'text' => $this->language->get('text_date_desc'), |
||
| 205 | 'value' => 'p.date_added-DESC', |
||
| 206 | 'href' => $this->url->link('blog/latest', '&sort=p.date_added&order=DESC' . $url) |
||
| 207 | ); |
||
| 208 | |||
| 209 | $data['sorts'][] = array( |
||
| 210 | 'text' => $this->language->get('text_viewed_desc'), |
||
| 211 | 'value' => 'p.viewed-DESC', |
||
| 212 | 'href' => $this->url->link('blog/latest', '&sort=p.viewed&order=DESC' . $url) |
||
| 213 | ); |
||
| 214 | |||
| 215 | $data['sorts'][] = array( |
||
| 216 | 'text' => $this->language->get('text_viewed_asc'), |
||
| 217 | 'value' => 'p.viewed-ASC', |
||
| 218 | 'href' => $this->url->link('blog/latest', '&sort=p.viewed&order=ASC' . $url) |
||
| 219 | ); |
||
| 220 | |||
| 221 | $url = ''; |
||
| 222 | |||
| 223 | if (isset($this->request->get['sort'])) { |
||
| 224 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 225 | } |
||
| 226 | |||
| 227 | if (isset($this->request->get['order'])) { |
||
| 228 | $url .= '&order=' . $this->request->get['order']; |
||
| 229 | } |
||
| 230 | |||
| 231 | $data['limits'] = array(); |
||
| 232 | |||
| 233 | $limits = array_unique(array($this->config->get('configblog_article_limit'), 25, 50, 75, 100)); |
||
| 234 | |||
| 235 | sort($limits); |
||
| 236 | |||
| 237 | foreach ($limits as $value) { |
||
| 238 | $data['limits'][] = array( |
||
| 239 | 'text' => $value, |
||
| 240 | 'value' => $value, |
||
| 241 | 'href' => $this->url->link('blog/latest', $url . '&limit=' . $value) |
||
| 242 | ); |
||
| 243 | } |
||
| 244 | |||
| 245 | $url = ''; |
||
| 246 | |||
| 247 | if (isset($this->request->get['sort'])) { |
||
| 248 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 249 | } |
||
| 250 | |||
| 251 | if (isset($this->request->get['order'])) { |
||
| 252 | $url .= '&order=' . $this->request->get['order']; |
||
| 253 | } |
||
| 254 | |||
| 255 | if (isset($this->request->get['limit'])) { |
||
| 256 | $url .= '&limit=' . $this->request->get['limit']; |
||
| 257 | } |
||
| 258 | |||
| 259 | $pagination = new \Divine\Engine\Library\Pagination(); |
||
| 260 | $pagination->total = $article_total; |
||
| 261 | $pagination->page = $page; |
||
| 262 | $pagination->limit = $limit; |
||
| 263 | $pagination->text = $this->language->get('text_pagination'); |
||
| 264 | $pagination->url = $this->url->link('blog/latest', $url . '&page={page}'); |
||
| 265 | |||
| 266 | $data['pagination'] = $pagination->render(); |
||
| 267 | |||
| 268 | $data['article_total'] = $article_total; |
||
| 269 | |||
| 270 | $data['continue'] = $this->url->link('common/home'); |
||
| 271 | |||
| 272 | $data['sort'] = $sort; |
||
| 273 | $data['order'] = $order; |
||
| 274 | $data['limit'] = $limit; |
||
| 275 | |||
| 276 | $data['column'] = $this->load->controller('common/column'); |
||
| 277 | |||
| 278 | $data['content_top'] = $this->load->controller('common/content_top'); |
||
| 279 | $data['content_bottom'] = $this->load->controller('common/content_bottom'); |
||
| 280 | $data['footer'] = $this->load->controller('common/footer'); |
||
| 281 | $data['header'] = $this->load->controller('common/header'); |
||
| 282 | |||
| 283 | $this->response->setOutput($this->load->view('blog/latest', $data)); |
||
| 284 | } |
||
| 286 |
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.