| Conditions | 8 |
| Paths | 16 |
| Total Lines | 108 |
| Code Lines | 68 |
| 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 | if (!$this->customer->isLogged()) { |
||
| 28 | $this->session->data['redirect'] = $this->url->link('account/download', '', true); |
||
| 29 | |||
| 30 | $this->response->redirect($this->url->link('account/login', '', true)); |
||
| 31 | } |
||
| 32 | |||
| 33 | $this->load->language('account/download'); |
||
| 34 | |||
| 35 | $this->document->setTitle($this->language->get('heading_title')); |
||
| 36 | |||
| 37 | $data['breadcrumbs'] = array(); |
||
| 38 | |||
| 39 | $data['breadcrumbs'][] = array( |
||
| 40 | 'text' => $this->language->get('text_home'), |
||
| 41 | 'href' => $this->url->link('common/home') |
||
| 42 | ); |
||
| 43 | |||
| 44 | $data['breadcrumbs'][] = array( |
||
| 45 | 'text' => $this->language->get('text_account'), |
||
| 46 | 'href' => $this->url->link('account/account', '', true) |
||
| 47 | ); |
||
| 48 | |||
| 49 | $data['breadcrumbs'][] = array( |
||
| 50 | 'text' => $this->language->get('text_downloads'), |
||
| 51 | 'href' => $this->url->link('account/download', '', true) |
||
| 52 | ); |
||
| 53 | |||
| 54 | $this->load->model('account/download'); |
||
| 55 | |||
| 56 | $data['heading_title'] = $this->language->get('heading_title'); |
||
| 57 | |||
| 58 | $data['text_empty'] = $this->language->get('text_empty'); |
||
| 59 | |||
| 60 | $data['column_order_id'] = $this->language->get('column_order_id'); |
||
| 61 | $data['column_name'] = $this->language->get('column_name'); |
||
| 62 | $data['column_size'] = $this->language->get('column_size'); |
||
| 63 | $data['column_date_added'] = $this->language->get('column_date_added'); |
||
| 64 | |||
| 65 | $data['button_download'] = $this->language->get('button_download'); |
||
| 66 | $data['button_continue'] = $this->language->get('button_continue'); |
||
| 67 | |||
| 68 | if (isset($this->request->get['page'])) { |
||
| 69 | $page = $this->request->get['page']; |
||
| 70 | } else { |
||
| 71 | $page = 1; |
||
| 72 | } |
||
| 73 | |||
| 74 | $data['downloads'] = array(); |
||
| 75 | |||
| 76 | $download_total = $this->model_account_download->getTotalDownloads(); |
||
| 77 | |||
| 78 | $results = $this->model_account_download->getDownloads(($page - 1) * $this->config->get('config_limit_store'), $this->config->get('config_limit_store')); |
||
| 79 | |||
| 80 | foreach ($results as $result) { |
||
| 81 | if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/storage/download/' . $result['filename'])) { |
||
| 82 | $size = filesize($_SERVER['DOCUMENT_ROOT'] . '/storage/download/' . $result['filename']); |
||
| 83 | |||
| 84 | $i = 0; |
||
| 85 | |||
| 86 | $suffix = array( |
||
| 87 | 'B', |
||
| 88 | 'KB', |
||
| 89 | 'MB', |
||
| 90 | 'GB', |
||
| 91 | 'TB', |
||
| 92 | 'PB', |
||
| 93 | 'EB', |
||
| 94 | 'ZB', |
||
| 95 | 'YB' |
||
| 96 | ); |
||
| 97 | |||
| 98 | while (($size / 1024) > 1) { |
||
| 99 | $size = $size / 1024; |
||
| 100 | $i++; |
||
| 101 | } |
||
| 102 | |||
| 103 | $data['downloads'][] = array( |
||
| 104 | 'order_id' => $result['order_id'], |
||
| 105 | 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), |
||
| 106 | 'name' => $result['name'], |
||
| 107 | 'size' => round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i], |
||
| 108 | 'href' => $this->url->link('account/download/download', 'download_id=' . $result['download_id'], true) |
||
| 109 | ); |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | $pagination = new \Divine\Engine\Library\Pagination(); |
||
| 114 | $pagination->total = $download_total; |
||
| 115 | $pagination->page = $page; |
||
| 116 | $pagination->limit = $this->config->get($this->config->get('config_theme') . '_product_limit'); |
||
| 117 | $pagination->url = $this->url->link('account/download', 'page={page}', true); |
||
| 118 | |||
| 119 | $data['pagination'] = $pagination->render(); |
||
| 120 | |||
| 121 | $data['results'] = sprintf($this->language->get('text_pagination'), ($download_total) ? (($page - 1) * $this->config->get($this->config->get('config_theme') . '_product_limit')) + 1 : 0, ((($page - 1) * $this->config->get($this->config->get('config_theme') . '_product_limit')) > ($download_total - $this->config->get($this->config->get('config_theme') . '_product_limit'))) ? $download_total : ((($page - 1) * $this->config->get($this->config->get('config_theme') . '_product_limit')) + $this->config->get($this->config->get($this->config->get('config_theme') . '_theme') . '_product_limit')), $download_total, ceil($download_total / $this->config->get($this->config->get('config_theme') . '_product_limit'))); |
||
| 122 | |||
| 123 | $data['continue'] = $this->url->link('account/account', '', true); |
||
| 124 | |||
| 125 | $data['column'] = $this->load->controller('common/column'); |
||
| 126 | |||
| 127 | $data['content_top'] = $this->load->controller('common/content_top'); |
||
| 128 | $data['content_bottom'] = $this->load->controller('common/content_bottom'); |
||
| 129 | $data['footer'] = $this->load->controller('common/footer'); |
||
| 130 | $data['header'] = $this->load->controller('common/header'); |
||
| 131 | |||
| 132 | $this->response->setOutput($this->load->view('account/download', $data)); |
||
| 133 | } |
||
| 184 |
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.