Conditions | 30 |
Paths | 6384 |
Total Lines | 280 |
Code Lines | 189 |
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 |
||
25 | public function index() |
||
26 | { |
||
27 | // styles (addStylePreload if "preload" or addStyle if not) |
||
28 | $this->document->addStyle('https://cdnjs.cloudflare.com/ajax/libs/uikit/3.1.6/css/uikit.min.css'); |
||
29 | $this->document->addStyle('/public_html/assets/css/application/general/styles.css'); |
||
30 | if (defined('SR_TRACY_DEBUG') && SR_TRACY_DEBUG == true) { |
||
31 | $this->document->addStyle('/public_html/assets/css/application/general/tracy-debugger.css'); |
||
32 | } |
||
33 | // scripts (addScriptDefer if "defer" or addScriptAsync if "async" or addScript if neither one nor the other) |
||
34 | $this->document->addScriptAsync('https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js'); |
||
35 | $this->document->addScriptAsync('https://cdnjs.cloudflare.com/ajax/libs/uikit/3.1.6/js/uikit.min.js'); |
||
36 | $this->document->addScriptDefer('https://cdnjs.cloudflare.com/ajax/libs/uikit/3.1.6/js/uikit-icons.min.js'); |
||
37 | $this->document->addScriptAsync('/public_html/assets/js/application/general/common/cart.js'); |
||
38 | // links | $this->document->addLink('/public_html/assets/images/' . $this->config->get('...'), 'icon'); |
||
39 | |||
40 | $data['title'] = $this->document->getTitle(); |
||
41 | |||
42 | $data['description'] = $this->document->getDescription(); |
||
43 | $data['links'] = $this->document->getLinks(); |
||
44 | $data['robots'] = $this->document->getRobots(); |
||
45 | |||
46 | $data['stylespreload'] = $this->document->getStylespreload(); |
||
47 | $data['styles'] = $this->document->getStyles(); |
||
48 | |||
49 | $data['scriptsasync'] = $this->document->getScriptsAsync(); |
||
50 | $data['scriptsdefer'] = $this->document->getScriptsDefer(); |
||
51 | $data['scripts'] = $this->document->getScripts(); |
||
52 | |||
53 | $data['lang'] = $this->language->get('code'); |
||
54 | $data['direction'] = $this->language->get('direction'); |
||
55 | |||
56 | $data['name'] = $this->config->get('config_name'); |
||
57 | |||
58 | if (is_file($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . $this->config->get('config_logo'))) { |
||
59 | $data['logo'] = '/public_html/assets/images/' . $this->config->get('config_logo'); |
||
60 | } else { |
||
61 | $data['logo'] = ''; |
||
62 | } |
||
63 | |||
64 | // language |
||
65 | $this->load->language('common/header'); |
||
66 | |||
67 | $data['test'] = $this->language->test(); |
||
68 | |||
69 | $data['text_home'] = $this->language->get('text_home'); |
||
70 | $data['text_shopping_cart'] = $this->language->get('text_shopping_cart'); |
||
71 | $data['text_logged'] = sprintf( |
||
72 | $this->language->get('text_logged'), |
||
73 | $this->url->link('account/account', '', true), |
||
74 | $this->customer->getFirstName(), |
||
75 | $this->url->link('account/logout', '', true) |
||
76 | ); |
||
77 | $data['text_account'] = $this->language->get('text_account'); |
||
78 | $data['text_register'] = $this->language->get('text_register'); |
||
79 | $data['text_login'] = $this->language->get('text_login'); |
||
80 | $data['text_order'] = $this->language->get('text_order'); |
||
81 | $data['text_transaction'] = $this->language->get('text_transaction'); |
||
82 | $data['text_download'] = $this->language->get('text_download'); |
||
83 | $data['text_logout'] = $this->language->get('text_logout'); |
||
84 | $data['text_checkout'] = $this->language->get('text_checkout'); |
||
85 | $data['text_main_menu'] = $this->language->get('text_main_menu'); |
||
86 | $data['text_go_to'] = $this->language->get('text_go_to'); |
||
87 | $data['text_look_at_map'] = $this->language->get('text_look_at_map'); |
||
88 | // |
||
89 | |||
90 | // links |
||
91 | $data['home'] = $this->url->link('common/home'); |
||
92 | $data['logged'] = $this->customer->isLogged(); |
||
93 | $data['account'] = $this->url->link('account/account', '', true); |
||
94 | $data['register'] = $this->url->link('account/register', '', true); |
||
95 | $data['login'] = $this->url->link('account/login', '', true); |
||
96 | $data['order'] = $this->url->link('account/order', '', true); |
||
97 | $data['transaction'] = $this->url->link('account/transaction', '', true); |
||
98 | $data['download'] = $this->url->link('account/download', '', true); |
||
99 | $data['logout'] = $this->url->link('account/logout', '', true); |
||
100 | $data['shopping_cart'] = $this->url->link('checkout/cart'); |
||
101 | // $data['checkout'] = $this->url->link('checkout/checkout', '', true); |
||
102 | $data['checkout'] = $this->url->link('checkout/onepagecheckout', '', true); |
||
103 | // |
||
104 | $data['contact'] = $this->url->link('information/contact'); |
||
105 | $data['telephone'] = $this->config->get('config_telephone'); |
||
106 | // |
||
107 | |||
108 | // Menu |
||
109 | $this->load->model('design/custommenu'); |
||
110 | $this->load->model('catalog/category'); |
||
111 | |||
112 | $this->load->model('catalog/product'); |
||
113 | |||
114 | $data['categories'] = array(); |
||
115 | |||
116 | if ($this->config->get('configcustommenu_custommenu')) { |
||
117 | $custommenus = $this->model_design_custommenu->getcustommenus(); |
||
118 | $custommenu_child = $this->model_design_custommenu->getChildcustommenus(); |
||
119 | |||
120 | foreach ($custommenus as $id => $custommenu) { |
||
121 | $children_data = array(); |
||
122 | |||
123 | foreach ($custommenu_child as $child_id => $child_custommenu) { |
||
124 | if (($custommenu['custommenu_id'] != $child_custommenu['custommenu_id']) or !is_numeric($child_id)) { |
||
125 | continue; |
||
126 | } |
||
127 | |||
128 | $child_name = ''; |
||
129 | |||
130 | if (($custommenu['custommenu_type'] == 'category') and ($child_custommenu['custommenu_type'] == 'category')) { |
||
131 | $filter_data = array( |
||
132 | 'filter_category_id' => $child_custommenu['link'], |
||
133 | 'filter_sub_category' => true |
||
134 | ); |
||
135 | |||
136 | $child_name = ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''); |
||
137 | } |
||
138 | |||
139 | $children_data[] = array( |
||
140 | 'name' => $child_custommenu['name'] . $child_name, |
||
141 | 'href' => $this->getcustommenuLink($custommenu, $child_custommenu) |
||
142 | ); |
||
143 | } |
||
144 | |||
145 | $data['categories'][] = array( |
||
146 | 'name' => $custommenu['name'], |
||
147 | 'children' => $children_data, |
||
148 | 'column' => $custommenu['columns'] ? $custommenu['columns'] : 1, |
||
149 | 'href' => $this->getcustommenuLink($custommenu) |
||
150 | ); |
||
151 | } |
||
152 | } else { |
||
153 | $categories = $this->model_catalog_category->getCategories(0); |
||
154 | |||
155 | foreach ($categories as $category) { |
||
156 | if ($category['top']) { |
||
157 | |||
158 | // Level 2 |
||
159 | $children_data = array(); |
||
160 | |||
161 | $children = $this->model_catalog_category->getCategories($category['category_id']); |
||
162 | |||
163 | foreach ($children as $child) { |
||
164 | $filter_data = array( |
||
165 | 'filter_category_id' => $child['category_id'], |
||
166 | 'filter_sub_category' => true |
||
167 | ); |
||
168 | |||
169 | $children_data[] = array( |
||
170 | 'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''), |
||
171 | 'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']) |
||
172 | ); |
||
173 | } |
||
174 | |||
175 | // Level 1 |
||
176 | $data['categories'][] = array( |
||
177 | 'name' => $category['name'], |
||
178 | 'children' => $children_data, |
||
179 | 'column' => $category['column'] ? $category['column'] : 1, |
||
180 | 'href' => $this->url->link('product/category', 'path=' . $category['category_id']) |
||
181 | ); |
||
182 | } |
||
183 | } |
||
184 | } |
||
185 | |||
186 | if ($this->config->get('configblog_blog_menu')) { |
||
187 | $data['menu'] = $this->load->controller('blog/menu'); |
||
188 | } else { |
||
189 | $data['menu'] = ''; |
||
190 | } |
||
191 | // |
||
192 | |||
193 | // adminbar |
||
194 | if (isset($this->session->data['token'])) { |
||
195 | |||
196 | // token |
||
197 | $data['token_admin'] = $this->session->data['token']; |
||
198 | // |
||
199 | |||
200 | // route |
||
201 | if (isset($this->request->get['route'])) { |
||
202 | if ($this->request->get['route'] == 'product/product') { |
||
203 | $data['quick_edit_admin'] = '/administration/index.php?route=catalog/product/edit&product_id=' . $this->request->get['product_id'] . '&token=' . $data['token_admin']; |
||
204 | } elseif ($this->request->get['route'] == 'product/category') { |
||
205 | $path_parts = explode('_', $this->request->get['path']); |
||
206 | $data['quick_edit_admin'] = '/administration/index.php?route=catalog/category/edit&category_id=' . array_pop($path_parts) . '&token=' . $data['token_admin']; |
||
207 | } elseif ($this->request->get['route'] == 'information/information') { |
||
208 | $data['quick_edit_admin'] = '/administration/index.php?route=catalog/information/edit&information_id=' . $this->request->get['information_id'] . '&token=' . $data['token_admin']; |
||
209 | } elseif ($this->request->get['route'] == 'product/manufacturer/info') { |
||
210 | $data['quick_edit_admin'] = '/administration/index.php?route=catalog/manufacturer/edit&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&token=' . $data['token_admin']; |
||
211 | } else { |
||
212 | $data['quick_edit_admin'] = ''; |
||
213 | } |
||
214 | } else { |
||
215 | $data['quick_edit_admin'] = ''; |
||
216 | } |
||
217 | // |
||
218 | |||
219 | // links |
||
220 | $data['dashboard_admin'] = '/administration/index.php?route=common/dashboard&token=' . $data['token_admin']; |
||
221 | $data['category_add_admin'] = '/administration/index.php?route=catalog/category/add&token=' . $data['token_admin']; |
||
222 | $data['product_add_admin'] = '/administration/index.php?route=catalog/product/add&token=' . $data['token_admin']; |
||
223 | $data['filter_add_admin'] = '/administration/index.php?route=catalog/filter/add&token=' . $data['token_admin']; |
||
224 | $data['attribute_add_admin'] = '/administration/index.php?route=catalog/attribute/add&token=' . $data['token_admin']; |
||
225 | $data['option_add_admin'] = '/administration/index.php?route=catalog/option/add&token=' . $data['token_admin']; |
||
226 | $data['manufacturer_add_admin'] = '/administration/index.php?route=catalog/manufacturer/add&token=' . $data['token_admin']; |
||
227 | $data['information_add_admin'] = '/administration/index.php?route=catalog/information/add&token=' . $data['token_admin']; |
||
228 | $data['category_all_admin'] = '/administration/index.php?route=catalog/category&token=' . $data['token_admin']; |
||
229 | $data['product_all_admin'] = '/administration/index.php?route=catalog/product&token=' . $data['token_admin']; |
||
230 | $data['filter_all_admin'] = '/administration/index.php?route=catalog/filter&token=' . $data['token_admin']; |
||
231 | $data['attribute_all_admin'] = '/administration/index.php?route=catalog/attribute&token=' . $data['token_admin']; |
||
232 | $data['option_all_admin'] = '/administration/index.php?route=catalog/option&token=' . $data['token_admin']; |
||
233 | $data['manufacturer_all_admin'] = '/administration/index.php?route=catalog/manufacturer&token=' . $data['token_admin']; |
||
234 | $data['review_all_admin'] = '/administration/index.php?route=catalog/review&token=' . $data['token_admin']; |
||
235 | $data['information_all_admin'] = '/administration/index.php?route=catalog/information&token=' . $data['token_admin']; |
||
236 | $data['orders_pending_admin'] = '/administration/index.php?route=sale/order&token=' . $data['token_admin'] . '&filter_order_status=1'; |
||
237 | $data['orders_processing_admin'] = '/administration/index.php?route=sale/order&token=' . $data['token_admin'] . '&filter_order_status=1'; |
||
238 | $data['orders_orders_today'] = '/administration/index.php?route=sale/order&token=' . $data['token_admin'] . '&filter_date_added=' . date('Y-m-d'); |
||
239 | $data['all_orders_admin'] = '/administration/index.php?route=sale/order&token=' . $data['token_admin']; |
||
240 | $data['return_admin'] = '/administration/index.php?route=sale/return&token=' . $data['token_admin']; |
||
241 | $data['adminbar_logout'] = '/administration/index.php?route=common/logout&token=' . $data['token_admin']; |
||
242 | // |
||
243 | |||
244 | // language |
||
245 | $data['text_adminbar_edit'] = $this->language->get('text_adminbar_edit'); |
||
246 | $data['text_adminbar_dashboard'] = $this->language->get('text_adminbar_dashboard'); |
||
247 | $data['text_adminbar_add'] = $this->language->get('text_adminbar_add'); |
||
248 | $data['text_adminbar_category'] = $this->language->get('text_adminbar_category'); |
||
249 | $data['text_adminbar_product'] = $this->language->get('text_adminbar_product'); |
||
250 | $data['text_adminbar_filter'] = $this->language->get('text_adminbar_filter'); |
||
251 | $data['text_adminbar_attribute'] = $this->language->get('text_adminbar_attribute'); |
||
252 | $data['text_adminbar_option'] = $this->language->get('text_adminbar_option'); |
||
253 | $data['text_adminbar_manufacturer'] = $this->language->get('text_adminbar_manufacturer'); |
||
254 | $data['text_adminbar_information'] = $this->language->get('text_adminbar_information'); |
||
255 | $data['text_adminbar_catalog'] = $this->language->get('text_adminbar_catalog'); |
||
256 | $data['text_adminbar_categories'] = $this->language->get('text_adminbar_categories'); |
||
257 | $data['text_adminbar_products'] = $this->language->get('text_adminbar_products'); |
||
258 | $data['text_adminbar_filters'] = $this->language->get('text_adminbar_filters'); |
||
259 | $data['text_adminbar_attributes'] = $this->language->get('text_adminbar_attributes'); |
||
260 | $data['text_adminbar_options'] = $this->language->get('text_adminbar_options'); |
||
261 | $data['text_adminbar_manufacturers'] = $this->language->get('text_adminbar_manufacturers'); |
||
262 | $data['text_adminbar_review'] = $this->language->get('text_adminbar_review'); |
||
263 | $data['text_adminbar_informations'] = $this->language->get('text_adminbar_informations'); |
||
264 | $data['text_adminbar_sale'] = $this->language->get('text_adminbar_sale'); |
||
265 | $data['text_adminbar_orders_pending'] = $this->language->get('text_adminbar_orders_pending'); |
||
266 | $data['text_adminbar_orders_processing'] = $this->language->get('text_adminbar_orders_processing'); |
||
267 | $data['text_adminbar_orders_today'] = $this->language->get('text_adminbar_orders_today'); |
||
268 | $data['text_adminbar_all_orders'] = $this->language->get('text_adminbar_all_orders'); |
||
269 | $data['text_adminbar_return'] = $this->language->get('text_adminbar_return'); |
||
270 | $data['text_adminbar_logout'] = $this->language->get('text_adminbar_logout'); |
||
271 | // |
||
272 | } |
||
273 | // |
||
274 | |||
275 | // For page specific css |
||
276 | if (isset($this->request->get['route'])) { |
||
277 | if (isset($this->request->get['product_id'])) { |
||
278 | $class = '-' . $this->request->get['product_id']; |
||
279 | } elseif (isset($this->request->get['path'])) { |
||
280 | $class = '-' . $this->request->get['path']; |
||
281 | } elseif (isset($this->request->get['manufacturer_id'])) { |
||
282 | $class = '-' . $this->request->get['manufacturer_id']; |
||
283 | } elseif (isset($this->request->get['information_id'])) { |
||
284 | $class = '-' . $this->request->get['information_id']; |
||
285 | } else { |
||
286 | $class = ''; |
||
287 | } |
||
288 | |||
289 | $data['class'] = str_replace('/', '-', $this->request->get['route']) . $class; |
||
290 | } else { |
||
291 | $data['class'] = 'common-home'; |
||
292 | } |
||
293 | // |
||
294 | |||
295 | // https://opencartforum.com/topic/129529-reliz-ocstore-3020/?do=findComment&comment=1313914 |
||
296 | $data['search'] = $this->load->controller('common/search'); |
||
297 | $data['cart'] = $this->load->controller('common/cart'); |
||
298 | // |
||
299 | |||
300 | echo '<!--'; |
||
301 | print_r($this->session); |
||
302 | echo '-->'; |
||
303 | |||
304 | return $this->load->view('common/header', $data); |
||
305 | } |
||
362 |
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.