Conditions | 23 |
Paths | > 20000 |
Total Lines | 161 |
Code Lines | 105 |
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 | if (!$this->customer->isLogged()) { |
||
30 | $this->session->data['redirect'] = $this->url->link('account/edit', '', true); |
||
31 | |||
32 | $this->response->redirect($this->url->link('account/login', '', true)); |
||
33 | } |
||
34 | |||
35 | $this->load->language('account/edit'); |
||
36 | |||
37 | $this->document->setTitle($this->language->get('heading_title')); |
||
38 | |||
39 | $this->load->model('account/customer'); |
||
40 | |||
41 | if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { |
||
42 | $this->model_account_customer->editCustomer($this->request->post); |
||
43 | |||
44 | $this->session->data['success'] = $this->language->get('text_success'); |
||
45 | |||
46 | $this->response->redirect($this->url->link('account/account', '', true)); |
||
47 | } |
||
48 | |||
49 | $data['breadcrumbs'] = array(); |
||
50 | |||
51 | $data['breadcrumbs'][] = array( |
||
52 | 'text' => $this->language->get('text_home'), |
||
53 | 'href' => $this->url->link('common/home') |
||
54 | ); |
||
55 | |||
56 | $data['breadcrumbs'][] = array( |
||
57 | 'text' => $this->language->get('text_account'), |
||
58 | 'href' => $this->url->link('account/account', '', true) |
||
59 | ); |
||
60 | |||
61 | $data['breadcrumbs'][] = array( |
||
62 | 'text' => $this->language->get('text_edit'), |
||
63 | 'href' => $this->url->link('account/edit', '', true) |
||
64 | ); |
||
65 | |||
66 | $data['heading_title'] = $this->language->get('heading_title'); |
||
67 | |||
68 | $data['text_your_details'] = $this->language->get('text_your_details'); |
||
69 | $data['text_additional'] = $this->language->get('text_additional'); |
||
70 | $data['text_select'] = $this->language->get('text_select'); |
||
71 | $data['text_loading'] = $this->language->get('text_loading'); |
||
72 | |||
73 | $data['entry_firstname'] = $this->language->get('entry_firstname'); |
||
74 | $data['entry_lastname'] = $this->language->get('entry_lastname'); |
||
75 | $data['entry_email'] = $this->language->get('entry_email'); |
||
76 | $data['entry_telephone'] = $this->language->get('entry_telephone'); |
||
77 | $data['entry_fax'] = $this->language->get('entry_fax'); |
||
78 | |||
79 | $data['button_continue'] = $this->language->get('button_continue'); |
||
80 | $data['button_back'] = $this->language->get('button_back'); |
||
81 | $data['button_upload'] = $this->language->get('button_upload'); |
||
82 | |||
83 | if (isset($this->error['warning'])) { |
||
84 | $data['error_warning'] = $this->error['warning']; |
||
85 | } else { |
||
86 | $data['error_warning'] = ''; |
||
87 | } |
||
88 | |||
89 | if (isset($this->error['firstname'])) { |
||
90 | $data['error_firstname'] = $this->error['firstname']; |
||
91 | } else { |
||
92 | $data['error_firstname'] = ''; |
||
93 | } |
||
94 | |||
95 | if (isset($this->error['lastname'])) { |
||
96 | $data['error_lastname'] = $this->error['lastname']; |
||
97 | } else { |
||
98 | $data['error_lastname'] = ''; |
||
99 | } |
||
100 | |||
101 | if (isset($this->error['email'])) { |
||
102 | $data['error_email'] = $this->error['email']; |
||
103 | } else { |
||
104 | $data['error_email'] = ''; |
||
105 | } |
||
106 | |||
107 | if (isset($this->error['telephone'])) { |
||
108 | $data['error_telephone'] = $this->error['telephone']; |
||
109 | } else { |
||
110 | $data['error_telephone'] = ''; |
||
111 | } |
||
112 | |||
113 | if (isset($this->error['custom_field'])) { |
||
114 | $data['error_custom_field'] = $this->error['custom_field']; |
||
115 | } else { |
||
116 | $data['error_custom_field'] = array(); |
||
117 | } |
||
118 | |||
119 | $data['action'] = $this->url->link('account/edit', '', true); |
||
120 | |||
121 | if ($this->request->server['REQUEST_METHOD'] != 'POST') { |
||
122 | $customer_info = $this->model_account_customer->getCustomer($this->customer->getId()); |
||
123 | } |
||
124 | |||
125 | if (isset($this->request->post['firstname'])) { |
||
126 | $data['firstname'] = $this->request->post['firstname']; |
||
127 | } elseif (!empty($customer_info)) { |
||
128 | $data['firstname'] = $customer_info['firstname']; |
||
129 | } else { |
||
130 | $data['firstname'] = ''; |
||
131 | } |
||
132 | |||
133 | if (isset($this->request->post['lastname'])) { |
||
134 | $data['lastname'] = $this->request->post['lastname']; |
||
135 | } elseif (!empty($customer_info)) { |
||
136 | $data['lastname'] = $customer_info['lastname']; |
||
137 | } else { |
||
138 | $data['lastname'] = ''; |
||
139 | } |
||
140 | |||
141 | if (isset($this->request->post['email'])) { |
||
142 | $data['email'] = $this->request->post['email']; |
||
143 | } elseif (!empty($customer_info)) { |
||
144 | $data['email'] = $customer_info['email']; |
||
145 | } else { |
||
146 | $data['email'] = ''; |
||
147 | } |
||
148 | |||
149 | if (isset($this->request->post['telephone'])) { |
||
150 | $data['telephone'] = $this->request->post['telephone']; |
||
151 | } elseif (!empty($customer_info)) { |
||
152 | $data['telephone'] = $customer_info['telephone']; |
||
153 | } else { |
||
154 | $data['telephone'] = ''; |
||
155 | } |
||
156 | |||
157 | if (isset($this->request->post['fax'])) { |
||
158 | $data['fax'] = $this->request->post['fax']; |
||
159 | } elseif (!empty($customer_info)) { |
||
160 | $data['fax'] = $customer_info['fax']; |
||
161 | } else { |
||
162 | $data['fax'] = ''; |
||
163 | } |
||
164 | |||
165 | // Custom Fields |
||
166 | $this->load->model('account/custom_field'); |
||
167 | |||
168 | $data['custom_fields'] = $this->model_account_custom_field->getCustomFields($this->config->get('config_customer_group_id')); |
||
169 | |||
170 | if (isset($this->request->post['custom_field'])) { |
||
171 | $data['account_custom_field'] = $this->request->post['custom_field']; |
||
172 | } elseif (isset($customer_info)) { |
||
173 | $data['account_custom_field'] = json_decode($customer_info['custom_field'], true); |
||
174 | } else { |
||
175 | $data['account_custom_field'] = array(); |
||
176 | } |
||
177 | |||
178 | $data['back'] = $this->url->link('account/account', '', true); |
||
179 | |||
180 | $data['column'] = $this->load->controller('common/column'); |
||
181 | |||
182 | $data['content_top'] = $this->load->controller('common/content_top'); |
||
183 | $data['content_bottom'] = $this->load->controller('common/content_bottom'); |
||
184 | $data['footer'] = $this->load->controller('common/footer'); |
||
185 | $data['header'] = $this->load->controller('common/header'); |
||
186 | |||
187 | $this->response->setOutput($this->load->view('account/edit', $data)); |
||
188 | } |
||
228 |
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.