| Conditions | 10 |
| Paths | 32 |
| Total Lines | 71 |
| Code Lines | 41 |
| 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 | $this->load->language('checkout/checkout'); |
||
|
|
|||
| 28 | |||
| 29 | if (isset($this->session->data['shipping_address'])) { |
||
| 30 | // Shipping Methods |
||
| 31 | $method_data = array(); |
||
| 32 | |||
| 33 | $this->load->model('extension/extension'); |
||
| 34 | |||
| 35 | $results = $this->model_extension_extension->getExtensions('shipping'); |
||
| 36 | |||
| 37 | foreach ($results as $result) { |
||
| 38 | if ($this->config->get($result['code'] . '_status')) { |
||
| 39 | $this->load->model('extension/shipping/' . $result['code']); |
||
| 40 | |||
| 41 | $quote = $this->{'model_extension_shipping_' . $result['code']}->getQuote($this->session->data['shipping_address']); |
||
| 42 | |||
| 43 | if ($quote) { |
||
| 44 | $method_data[$result['code']] = array( |
||
| 45 | 'title' => $quote['title'], |
||
| 46 | 'quote' => $quote['quote'], |
||
| 47 | 'sort_order' => $quote['sort_order'], |
||
| 48 | 'error' => $quote['error'] |
||
| 49 | ); |
||
| 50 | } |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | $sort_order = array(); |
||
| 55 | |||
| 56 | foreach ($method_data as $key => $value) { |
||
| 57 | $sort_order[$key] = $value['sort_order']; |
||
| 58 | } |
||
| 59 | |||
| 60 | array_multisort($sort_order, SORT_ASC, $method_data); |
||
| 61 | |||
| 62 | $this->session->data['shipping_methods'] = $method_data; |
||
| 63 | } |
||
| 64 | |||
| 65 | $data['text_shipping_method'] = $this->language->get('text_shipping_method'); |
||
| 66 | $data['text_comments'] = $this->language->get('text_comments'); |
||
| 67 | $data['text_loading'] = $this->language->get('text_loading'); |
||
| 68 | |||
| 69 | $data['button_continue'] = $this->language->get('button_continue'); |
||
| 70 | |||
| 71 | if (empty($this->session->data['shipping_methods'])) { |
||
| 72 | $data['error_warning'] = sprintf($this->language->get('error_no_shipping'), $this->url->link('information/contact')); |
||
| 73 | } else { |
||
| 74 | $data['error_warning'] = ''; |
||
| 75 | } |
||
| 76 | |||
| 77 | if (isset($this->session->data['shipping_methods'])) { |
||
| 78 | $data['shipping_methods'] = $this->session->data['shipping_methods']; |
||
| 79 | } else { |
||
| 80 | $data['shipping_methods'] = array(); |
||
| 81 | } |
||
| 82 | |||
| 83 | if (isset($this->session->data['shipping_method']['code'])) { |
||
| 84 | $data['code'] = $this->session->data['shipping_method']['code']; |
||
| 85 | } else { |
||
| 86 | $data['code'] = ''; |
||
| 87 | } |
||
| 88 | |||
| 89 | if (isset($this->session->data['comment'])) { |
||
| 90 | $data['comment'] = $this->session->data['comment']; |
||
| 91 | } else { |
||
| 92 | $data['comment'] = ''; |
||
| 93 | } |
||
| 94 | |||
| 95 | $this->response->setOutput($this->load->view('checkout/shipping_method', $data)); |
||
| 96 | } |
||
| 158 |