Conditions | 12 |
Paths | 8 |
Total Lines | 126 |
Code Lines | 89 |
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 addCustomer($data) |
||
26 | { |
||
27 | if (isset($data['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($data['customer_group_id'], $this->config->get('config_customer_group_display'))) { |
||
28 | $customer_group_id = $data['customer_group_id']; |
||
29 | } else { |
||
30 | $customer_group_id = $this->config->get('config_customer_group_id'); |
||
31 | } |
||
32 | |||
33 | $this->load->model('account/customer_group'); |
||
34 | |||
35 | $customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id); |
||
36 | |||
37 | $this->db->query(" |
||
38 | INSERT INTO customer |
||
39 | SET customer_group_id = '" . (int)$customer_group_id . "', |
||
40 | language_id = '" . (int)$this->config->get('config_language_id') . "', |
||
41 | firstname = '" . $this->db->escape($data['firstname']) . "', |
||
42 | lastname = '" . $this->db->escape($data['lastname']) . "', |
||
43 | email = '" . $this->db->escape($data['email']) . "', |
||
44 | telephone = '" . $this->db->escape($data['telephone']) . "', |
||
45 | fax = '" . $this->db->escape($data['fax']) . "', |
||
46 | custom_field = '" . $this->db->escape(isset($data['custom_field']['account']) ? json_encode($data['custom_field']['account']) : '') . "', |
||
47 | salt = '" . $this->db->escape($salt = (new \Tokenly\TokenGenerator\TokenGenerator())->generateToken(9, 'SR')) . "', |
||
48 | password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($data['password'])))) . "', |
||
49 | newsletter = '" . (isset($data['newsletter']) ? (int)$data['newsletter'] : 0) . "', ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "', |
||
50 | status = '1', |
||
51 | approved = '" . (int)!$customer_group_info['approval'] . "', |
||
52 | date_added = NOW() |
||
53 | "); |
||
54 | |||
55 | $customer_id = $this->db->getLastId(); |
||
56 | |||
57 | $this->db->query(" |
||
58 | INSERT INTO address |
||
59 | SET customer_id = '" . (int)$customer_id . "', |
||
60 | firstname = '" . $this->db->escape($data['firstname']) . "', |
||
61 | lastname = '" . $this->db->escape($data['lastname']) . "', |
||
62 | company = '" . $this->db->escape($data['company']) . "', |
||
63 | address_1 = '" . $this->db->escape($data['address_1']) . "', |
||
64 | address_2 = '" . $this->db->escape($data['address_2']) . "', |
||
65 | city = '" . $this->db->escape($data['city']) . "', |
||
66 | postcode = '" . $this->db->escape($data['postcode']) . "', |
||
67 | country_id = '" . (int)$data['country_id'] . "', |
||
68 | zone_id = '" . (int)$data['zone_id'] . "', |
||
69 | custom_field = '" . $this->db->escape(isset($data['custom_field']['address']) ? json_encode($data['custom_field']['address']) : '') . "' |
||
70 | "); |
||
71 | |||
72 | $address_id = $this->db->getLastId(); |
||
73 | |||
74 | $this->db->query(" |
||
75 | UPDATE customer |
||
76 | SET address_id = '" . (int)$address_id . "' |
||
77 | WHERE customer_id = '" . (int)$customer_id . "' |
||
78 | "); |
||
79 | |||
80 | $this->load->language('mail/customer'); |
||
81 | |||
82 | $subject = sprintf($this->language->get('text_subject'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8')); |
||
83 | |||
84 | $message = sprintf($this->language->get('text_welcome'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8')) . "\n\n"; |
||
85 | |||
86 | if (!$customer_group_info['approval']) { |
||
87 | $message .= $this->language->get('text_login') . "\n"; |
||
88 | } else { |
||
89 | $message .= $this->language->get('text_approval') . "\n"; |
||
90 | } |
||
91 | |||
92 | $message .= $this->url->link('account/login', '', true) . "\n\n"; |
||
93 | $message .= $this->language->get('text_services') . "\n\n"; |
||
94 | $message .= $this->language->get('text_thanks') . "\n"; |
||
95 | $message .= html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'); |
||
96 | |||
97 | $mail = new \Divine\Engine\Library\Mail(); |
||
98 | $mail->protocol = $this->config->get('config_mail_protocol'); |
||
99 | $mail->parameter = $this->config->get('config_mail_parameter'); |
||
100 | $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); |
||
101 | $mail->smtp_username = $this->config->get('config_mail_smtp_username'); |
||
102 | $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); |
||
103 | $mail->smtp_port = $this->config->get('config_mail_smtp_port'); |
||
104 | $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); |
||
105 | |||
106 | $mail->setTo($data['email']); |
||
107 | $mail->setFrom($this->config->get('config_email')); |
||
108 | $mail->setSender(html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8')); |
||
109 | $mail->setSubject($subject); |
||
110 | $mail->setText($message); |
||
111 | $mail->send(); |
||
112 | |||
113 | // Send to main admin email if new account email is enabled |
||
114 | if (in_array('account', (array)$this->config->get('config_mail_alert'))) { |
||
115 | $message = $this->language->get('text_signup') . "\n\n"; |
||
116 | $message .= $this->language->get('text_website') . ' ' . html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8') . "\n"; |
||
117 | $message .= $this->language->get('text_firstname') . ' ' . $data['firstname'] . "\n"; |
||
118 | $message .= $this->language->get('text_lastname') . ' ' . $data['lastname'] . "\n"; |
||
119 | $message .= $this->language->get('text_customer_group') . ' ' . $customer_group_info['name'] . "\n"; |
||
120 | $message .= $this->language->get('text_email') . ' ' . $data['email'] . "\n"; |
||
121 | $message .= $this->language->get('text_telephone') . ' ' . $data['telephone'] . "\n"; |
||
122 | |||
123 | $mail = new \Divine\Engine\Library\Mail(); |
||
124 | $mail->protocol = $this->config->get('config_mail_protocol'); |
||
125 | $mail->parameter = $this->config->get('config_mail_parameter'); |
||
126 | $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); |
||
127 | $mail->smtp_username = $this->config->get('config_mail_smtp_username'); |
||
128 | $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); |
||
129 | $mail->smtp_port = $this->config->get('config_mail_smtp_port'); |
||
130 | $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); |
||
131 | |||
132 | $mail->setTo($this->config->get('config_email')); |
||
133 | $mail->setFrom($this->config->get('config_email')); |
||
134 | $mail->setSender(html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8')); |
||
135 | $mail->setSubject(html_entity_decode($this->language->get('text_new_customer'), ENT_QUOTES, 'UTF-8')); |
||
136 | $mail->setText($message); |
||
137 | $mail->send(); |
||
138 | |||
139 | // Send to additional alert emails if new account email is enabled |
||
140 | $emails = explode(',', $this->config->get('config_alert_email')); |
||
141 | |||
142 | foreach ($emails as $email) { |
||
143 | if (\voku\helper\UTF8::strlen($email) > 0 && filter_var($email, FILTER_VALIDATE_EMAIL)) { |
||
144 | $mail->setTo($email); |
||
145 | $mail->send(); |
||
146 | } |
||
147 | } |
||
148 | } |
||
149 | |||
150 | return $customer_id; |
||
151 | } |
||
324 |
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.