Conditions | 26 |
Paths | > 20000 |
Total Lines | 168 |
Code Lines | 110 |
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 |
||
27 | public function index() |
||
28 | { |
||
29 | $this->load->language('extension/module/featured'); |
||
30 | |||
31 | $this->document->setTitle($this->language->get('heading_title')); |
||
32 | |||
33 | $this->load->model('extension/module'); |
||
34 | |||
35 | if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { |
||
36 | if (!isset($this->request->get['module_id'])) { |
||
37 | $this->model_extension_module->addModule('featured', $this->request->post); |
||
38 | } else { |
||
39 | $this->model_extension_module->editModule($this->request->get['module_id'], $this->request->post); |
||
40 | } |
||
41 | |||
42 | $this->session->data['success'] = $this->language->get('text_success'); |
||
43 | |||
44 | $this->response->redirect($this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true)); |
||
45 | } |
||
46 | |||
47 | $data['heading_title'] = $this->language->get('heading_title'); |
||
48 | |||
49 | $data['text_edit'] = $this->language->get('text_edit'); |
||
50 | $data['text_enabled'] = $this->language->get('text_enabled'); |
||
51 | $data['text_disabled'] = $this->language->get('text_disabled'); |
||
52 | |||
53 | $data['entry_name'] = $this->language->get('entry_name'); |
||
54 | $data['entry_product'] = $this->language->get('entry_product'); |
||
55 | $data['entry_limit'] = $this->language->get('entry_limit'); |
||
56 | $data['entry_width'] = $this->language->get('entry_width'); |
||
57 | $data['entry_height'] = $this->language->get('entry_height'); |
||
58 | $data['entry_status'] = $this->language->get('entry_status'); |
||
59 | |||
60 | $data['help_product'] = $this->language->get('help_product'); |
||
61 | |||
62 | $data['button_save'] = $this->language->get('button_save'); |
||
63 | $data['button_cancel'] = $this->language->get('button_cancel'); |
||
64 | |||
65 | if (isset($this->error['warning'])) { |
||
66 | $data['error_warning'] = $this->error['warning']; |
||
67 | } else { |
||
68 | $data['error_warning'] = ''; |
||
69 | } |
||
70 | |||
71 | if (isset($this->error['name'])) { |
||
72 | $data['error_name'] = $this->error['name']; |
||
73 | } else { |
||
74 | $data['error_name'] = ''; |
||
75 | } |
||
76 | |||
77 | if (isset($this->error['width'])) { |
||
78 | $data['error_width'] = $this->error['width']; |
||
79 | } else { |
||
80 | $data['error_width'] = ''; |
||
81 | } |
||
82 | |||
83 | if (isset($this->error['height'])) { |
||
84 | $data['error_height'] = $this->error['height']; |
||
85 | } else { |
||
86 | $data['error_height'] = ''; |
||
87 | } |
||
88 | |||
89 | $data['breadcrumbs'] = array(); |
||
90 | |||
91 | $data['breadcrumbs'][] = array( |
||
92 | 'text' => $this->language->get('text_home'), |
||
93 | 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true) |
||
94 | ); |
||
95 | |||
96 | $data['breadcrumbs'][] = array( |
||
97 | 'text' => $this->language->get('text_extension'), |
||
98 | 'href' => $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true) |
||
99 | ); |
||
100 | |||
101 | if (!isset($this->request->get['module_id'])) { |
||
102 | $data['breadcrumbs'][] = array( |
||
103 | 'text' => $this->language->get('heading_title'), |
||
104 | 'href' => $this->url->link('extension/module/featured', 'token=' . $this->session->data['token'], true) |
||
105 | ); |
||
106 | } else { |
||
107 | $data['breadcrumbs'][] = array( |
||
108 | 'text' => $this->language->get('heading_title'), |
||
109 | 'href' => $this->url->link('extension/module/featured', 'token=' . $this->session->data['token'] . '&module_id=' . $this->request->get['module_id'], true) |
||
110 | ); |
||
111 | } |
||
112 | |||
113 | if (!isset($this->request->get['module_id'])) { |
||
114 | $data['action'] = $this->url->link('extension/module/featured', 'token=' . $this->session->data['token'], true); |
||
115 | } else { |
||
116 | $data['action'] = $this->url->link('extension/module/featured', 'token=' . $this->session->data['token'] . '&module_id=' . $this->request->get['module_id'], true); |
||
117 | } |
||
118 | |||
119 | $data['cancel'] = $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true); |
||
120 | |||
121 | if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { |
||
122 | $module_info = $this->model_extension_module->getModule($this->request->get['module_id']); |
||
123 | } |
||
124 | |||
125 | $data['token'] = $this->session->data['token']; |
||
126 | |||
127 | if (isset($this->request->post['name'])) { |
||
128 | $data['name'] = $this->request->post['name']; |
||
129 | } elseif (!empty($module_info)) { |
||
130 | $data['name'] = $module_info['name']; |
||
131 | } else { |
||
132 | $data['name'] = ''; |
||
133 | } |
||
134 | |||
135 | $this->load->model('catalog/product'); |
||
136 | |||
137 | $data['products'] = array(); |
||
138 | |||
139 | if (!empty($this->request->post['product'])) { |
||
140 | $products = $this->request->post['product']; |
||
141 | } elseif (!empty($module_info['product'])) { |
||
142 | $products = $module_info['product']; |
||
143 | } else { |
||
144 | $products = array(); |
||
145 | } |
||
146 | |||
147 | foreach ($products as $product_id) { |
||
148 | $product_info = $this->model_catalog_product->getProduct($product_id); |
||
149 | |||
150 | if ($product_info) { |
||
151 | $data['products'][] = array( |
||
152 | 'product_id' => $product_info['product_id'], |
||
153 | 'name' => $product_info['name'] |
||
154 | ); |
||
155 | } |
||
156 | } |
||
157 | |||
158 | if (isset($this->request->post['limit'])) { |
||
159 | $data['limit'] = $this->request->post['limit']; |
||
160 | } elseif (!empty($module_info)) { |
||
161 | $data['limit'] = $module_info['limit']; |
||
162 | } else { |
||
163 | $data['limit'] = 5; |
||
164 | } |
||
165 | |||
166 | if (isset($this->request->post['width'])) { |
||
167 | $data['width'] = $this->request->post['width']; |
||
168 | } elseif (!empty($module_info)) { |
||
169 | $data['width'] = $module_info['width']; |
||
170 | } else { |
||
171 | $data['width'] = 200; |
||
172 | } |
||
173 | |||
174 | if (isset($this->request->post['height'])) { |
||
175 | $data['height'] = $this->request->post['height']; |
||
176 | } elseif (!empty($module_info)) { |
||
177 | $data['height'] = $module_info['height']; |
||
178 | } else { |
||
179 | $data['height'] = 200; |
||
180 | } |
||
181 | |||
182 | if (isset($this->request->post['status'])) { |
||
183 | $data['status'] = $this->request->post['status']; |
||
184 | } elseif (!empty($module_info)) { |
||
185 | $data['status'] = $module_info['status']; |
||
186 | } else { |
||
187 | $data['status'] = ''; |
||
188 | } |
||
189 | |||
190 | $data['header'] = $this->load->controller('common/header'); |
||
191 | $data['column'] = $this->load->controller('common/column_left'); |
||
192 | $data['footer'] = $this->load->controller('common/footer'); |
||
193 | |||
194 | $this->response->setOutput($this->load->view('extension/module/featured', $data)); |
||
195 | } |
||
218 |
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.