| Conditions | 11 |
| Paths | 96 |
| Total Lines | 146 |
| 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 addOrder($data) |
||
| 26 | { |
||
| 27 | $this->db->query(" |
||
| 28 | INSERT INTO `order` |
||
| 29 | SET store_name = '" . $this->db->escape($data['store_name']) . "', |
||
| 30 | store_url = '" . $this->db->escape($data['store_url']) . "', |
||
| 31 | customer_id = '" . (int)$data['customer_id'] . "', |
||
| 32 | customer_group_id = '" . (int)$data['customer_group_id'] . "', |
||
| 33 | firstname = '" . $this->db->escape($data['firstname']) . "', |
||
| 34 | email = '" . $this->db->escape($data['email']) . "', |
||
| 35 | telephone = '" . $this->db->escape($data['telephone']) . "', |
||
| 36 | payment_firstname = '" . $this->db->escape($data['firstname']) . "', |
||
| 37 | payment_address_1 = '" . $this->db->escape($data['address_1']) . "', |
||
| 38 | payment_city = '" . $this->db->escape($data['city']) . "', |
||
| 39 | shipping_address_1 = '" . $this->db->escape($data['address_1']) . "', |
||
| 40 | shipping_city = '" . $this->db->escape($data['city']) . "', |
||
| 41 | shipping_method = '" . $this->db->escape($data['shipping_method']['title']) . "', |
||
| 42 | shipping_code = '" . $this->db->escape($data['shipping_method']['code']) . "', |
||
| 43 | payment_method = '" . $this->db->escape($data['payment_method']['title']) . "', |
||
| 44 | payment_code = '" . $this->db->escape($data['payment_method']['code']) . "', |
||
| 45 | payment_country='', |
||
| 46 | payment_country_id = '0', |
||
| 47 | payment_zone_id = '0', |
||
| 48 | shipping_country_id = '0', |
||
| 49 | shipping_zone_id = '0', |
||
| 50 | comment = '" . $this->db->escape($data['comment']) . "', |
||
| 51 | total = '" . (float)$data['cart_total'] . "', |
||
| 52 | language_id = '" . (int)$data['language_id'] . "', |
||
| 53 | currency_id = '" . (int)$data['currency_id'] . "', |
||
| 54 | currency_code = '" . $this->db->escape($data['currency_code']) . "', |
||
| 55 | currency_value = '" . (float)$data['currency_value'] . "', |
||
| 56 | order_status_id = '" . (int)$data['order_status_id'] . "', |
||
| 57 | ip = '" . $this->db->escape($data['ip']) . "', |
||
| 58 | forwarded_ip = '" . $this->db->escape($data['forwarded_ip']) . "', |
||
| 59 | user_agent = '" . $this->db->escape($data['user_agent']) . "', |
||
| 60 | accept_language = '" . $this->db->escape($data['accept_language']) . "', |
||
| 61 | date_added = NOW(), |
||
| 62 | date_modified = NOW() |
||
| 63 | "); |
||
| 64 | |||
| 65 | $order_id = $this->db->getLastId(); |
||
| 66 | |||
| 67 | // Products |
||
| 68 | if (isset($data['products'])) { |
||
| 69 | foreach ($data['products'] as $product) { |
||
| 70 | $this->db->query(" |
||
| 71 | INSERT INTO order_product |
||
| 72 | SET order_id = '" . (int)$order_id . "', |
||
| 73 | product_id = '" . (int)$product['product_id'] . "', |
||
| 74 | name = '" . $this->db->escape($product['name']) . "', |
||
| 75 | model = '" . $this->db->escape($product['model']) . "', |
||
| 76 | quantity = '" . (int)$product['quantity'] . "', |
||
| 77 | price = '" . (float)$product['price'] . "', |
||
| 78 | total = '" . (float)$product['total'] . "', |
||
| 79 | reward = '" . (int)$product['reward'] . "' |
||
| 80 | "); |
||
| 81 | |||
| 82 | $order_product_id = $this->db->getLastId(); |
||
| 83 | |||
| 84 | foreach ($product['option'] as $option) { |
||
| 85 | $this->db->query(" |
||
| 86 | INSERT INTO order_option |
||
| 87 | SET order_id = '" . (int)$order_id . "', |
||
| 88 | order_product_id = '" . (int)$order_product_id . "', |
||
| 89 | product_option_id = '" . (int)$option['product_option_id'] . "', |
||
| 90 | product_option_value_id = '" . (int)$option['product_option_value_id'] . "', |
||
| 91 | name = '" . $this->db->escape($option['name']) . "', |
||
| 92 | `value` = '" . $this->db->escape($option['value']) . "', |
||
| 93 | `type` = '" . $this->db->escape($option['type']) . "' |
||
| 94 | "); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | // Totals this is netver used |
||
| 100 | if (isset($data['cart_total']) && false) { |
||
| 101 | $this->db->query(" |
||
| 102 | INSERT INTO order_total |
||
| 103 | SET order_id = '" . (int)$order_id . "', |
||
| 104 | code = 'total', |
||
| 105 | title = 'Total', |
||
| 106 | `value` = '" . (float)$data['cart_total']."', |
||
| 107 | sort_order = '' |
||
| 108 | "); |
||
| 109 | $this->db->query(" |
||
| 110 | INSERT INTO order_total |
||
| 111 | SET order_id = '" . (int)$order_id . "', |
||
| 112 | code = 'sub_total', |
||
| 113 | title = 'Total', |
||
| 114 | `value` = '" . (float)$data['cart_total']."', |
||
| 115 | sort_order = '' |
||
| 116 | "); |
||
| 117 | } |
||
| 118 | $totals = array(); |
||
| 119 | // ex4 mod for totals |
||
| 120 | $total_data = array( |
||
| 121 | 'totals' => &$totals, |
||
| 122 | 'total' => &$total |
||
| 123 | ); |
||
| 124 | $sort_order = array(); |
||
| 125 | |||
| 126 | $results = $this->model_extension_extension->getExtensions('total'); |
||
| 127 | |||
| 128 | foreach ($results as $key => $value) { |
||
| 129 | $sort_order[$key] = $this->config->get($value['code'] . '_sort_order'); |
||
| 130 | } |
||
| 131 | |||
| 132 | array_multisort($sort_order, SORT_ASC, $results); |
||
| 133 | |||
| 134 | foreach ($results as $result) { |
||
| 135 | if ($this->config->get($result['code'] . '_status')) { |
||
| 136 | $this->load->model('extension/total/' . $result['code']); |
||
| 137 | |||
| 138 | // We have to put the totals in an array so that they pass by reference. |
||
| 139 | $this->{'model_extension_total_' . $result['code']}->getTotal($total_data); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | $sort_order = array(); |
||
| 144 | foreach ($totals as $key => $value) { |
||
| 145 | $sort_order[$key] = $value['sort_order']; |
||
| 146 | } |
||
| 147 | |||
| 148 | array_multisort($sort_order, SORT_ASC, $totals); |
||
| 149 | $i = 10; |
||
| 150 | $total_sum = 0; |
||
| 151 | foreach ($totals as $total) { |
||
| 152 | $this->db->query(" |
||
| 153 | INSERT INTO order_total |
||
| 154 | SET order_id = '" . (int)$order_id . "', |
||
| 155 | code = '".$total['code']."', |
||
| 156 | title = '".$total['title']."', |
||
| 157 | `value` = '" . (float)$total['value']."', |
||
| 158 | sort_order = '".$i."' |
||
| 159 | "); |
||
| 160 | $i += 10; |
||
| 161 | $total_sum = $total['value']; |
||
| 162 | } |
||
| 163 | // Last row in totals should be final sum... |
||
| 164 | $this->db->query(" |
||
| 165 | UPDATE order |
||
| 166 | SET total='".$total_sum."' |
||
| 167 | WHERE order_id = '" . (int)$order_id . "' |
||
| 168 | "); |
||
| 169 | |||
| 170 | return $order_id; |
||
| 171 | } |
||
| 173 |
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.