| Conditions | 37 |
| Paths | > 20000 |
| Total Lines | 126 |
| Code Lines | 88 |
| Lines | 15 |
| Ratio | 11.9 % |
| 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 |
||
| 56 | function index() { |
||
| 57 | if ($this->session->userdata('user_login') == FALSE) { |
||
| 58 | if (!empty($_POST) && trim($_POST['username']) != '' && trim($_POST['password']) != '') { |
||
| 59 | $_POST['password']=$this->common->encode($_POST['password']); |
||
| 60 | $user_valid = $this->Auth_model->verify_login($_POST['username'], $_POST['password']); |
||
| 61 | |||
| 62 | if ($user_valid == 1) { |
||
| 63 | $this->session->set_userdata('user_login', TRUE); |
||
| 64 | $where = "number = '".$this->db->escape_str($_POST['username'])."' OR email = '".$this->db->escape_str($_POST['username'])."'"; |
||
| 65 | $result = $this->db_model->getSelect("*", "accounts",$where); |
||
| 66 | $result = $result->result_array(); |
||
| 67 | $result = $result[0]; |
||
| 68 | $logintype=$result['type']== -1 ? 2: $result['type']; |
||
| 69 | $this->session->set_userdata('logintype', $logintype); |
||
| 70 | $this->session->set_userdata('userlevel_logintype', $result['type']); |
||
| 71 | $this->session->set_userdata('username', $_POST['username']); |
||
| 72 | $this->session->set_userdata('accountinfo', $result); |
||
| 73 | /* |
||
| 74 | * |
||
| 75 | * Purpose : Display logo based on domain name |
||
| 76 | * |
||
| 77 | */ |
||
| 78 | $this->db->select("*"); |
||
| 79 | if ($result['type'] == '2' || $result['type'] == '-1') { |
||
| 80 | $this->db->where(array("accountid"=>$result["id"])); |
||
| 81 | } else if ($result['type'] == '0') { |
||
| 82 | View Code Duplication | if ($result['reseller_id'] == 0) { |
|
| 83 | $this->db->where(array("accountid"=>"1")); |
||
| 84 | } else { |
||
| 85 | $this->db->where(array("accountid"=>$result["reseller_id"])); |
||
| 86 | } |
||
| 87 | } else if ($result['type'] == '1') { |
||
| 88 | if ($result['reseller_id'] == 0) { |
||
| 89 | $result_invoice = $this->common->get_field_name('id', 'invoice_conf', array("accountid" => $result['id'])); |
||
| 90 | |||
| 91 | View Code Duplication | if ($result_invoice) { |
|
| 92 | $this->db->where(array("accountid"=>$result["id"])); |
||
| 93 | } else { |
||
| 94 | $this->db->where(array("accountid"=>"1")); |
||
| 95 | } |
||
| 96 | |||
| 97 | } else { |
||
| 98 | $result_invoice = $this->common->get_field_name('id', 'invoice_conf', array("accountid" => $result['reseller_id'])); |
||
| 99 | View Code Duplication | if ($result_invoice) { |
|
| 100 | $this->db->where(array("accountid"=>$result["reseller_id"])); |
||
| 101 | } else { |
||
| 102 | $this->db->where(array("accountid"=>"1")); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | } else { |
||
| 106 | $this->db->where(array("accountid"=>"1")); |
||
| 107 | } |
||
| 108 | $res = $this->db->get("invoice_conf"); |
||
| 109 | $logo_arr = $res->result(); |
||
| 110 | $data['user_logo'] = (isset($logo_arr[0]->logo) && $logo_arr[0]->logo != "") ? $logo_arr[0]->accountid."_".$logo_arr[0]->logo : "logo.png"; |
||
| 111 | $data['user_header'] = (isset($logo_arr[0]->website_title) && $logo_arr[0]->website_title != "") ? $logo_arr[0]->website_title : "ASTPP - Open Source Voip Billing Solution"; |
||
| 112 | $data['user_footer'] = (isset($logo_arr[0]->website_footer) && $logo_arr[0]->website_footer != "") ? $logo_arr[0]->website_footer : "Inextrix Technologies Pvt. Ltd All Rights Reserved."; |
||
| 113 | $this->session->set_userdata('user_logo', $data['user_logo']); |
||
| 114 | $this->session->set_userdata('user_header', $data['user_header']); |
||
| 115 | $this->session->set_userdata('user_footer', $data['user_footer']); |
||
| 116 | // echo $data['user_header'];exit; |
||
| 117 | /***************************************************************************************/ |
||
| 118 | if ($result['type'] == 0 || $result['type'] == 1) { |
||
| 119 | $menu_list = $this->permission->get_module_access($result['type']); |
||
| 120 | $this->session->set_userdata('mode_cur', 'user'); |
||
| 121 | if($result['type'] == 1){ |
||
| 122 | redirect(base_url() . 'dashboard/'); |
||
| 123 | }else{ |
||
| 124 | redirect(base_url() . 'user/user/'); |
||
| 125 | } |
||
| 126 | } else { |
||
| 127 | $menu_list = $this->permission->get_module_access($result['type']); |
||
| 128 | $this->session->set_userdata('mode_cur', 'admin'); |
||
| 129 | redirect(base_url() . 'dashboard/'); |
||
| 130 | } |
||
| 131 | } else { |
||
| 132 | |||
| 133 | $data['astpp_notification'] = "Login Failed! Try Again.."; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | /* |
||
| 137 | * Purpose : Display logo based on domain name |
||
| 138 | */ |
||
| 139 | $this->db->select("*"); |
||
| 140 | $this->db->where(array("domain"=>$_SERVER["HTTP_HOST"])); |
||
| 141 | $res = $this->db->get("invoice_conf"); |
||
| 142 | $logo_arr = $res->result(); |
||
| 143 | $data['user_logo'] = (isset($logo_arr[0]->logo) && $logo_arr[0]->logo != "") ? $logo_arr[0]->accountid."_".$logo_arr[0]->logo : "logo.png"; |
||
| 144 | $data['website_header'] = (isset($logo_arr[0]->website_title) && $logo_arr[0]->website_title != "") ? $logo_arr[0]->website_title : "ASTPP - Open Source Voip Billing Solution"; |
||
| 145 | $data['website_footer'] = (isset($logo_arr[0]->website_footer) && $logo_arr[0]->website_footer != "") ? $logo_arr[0]->website_footer : "Inextrix Technologies Pvt. Ltd All Rights Reserved."; |
||
| 146 | $this->session->set_userdata('user_logo', $data['user_logo']); |
||
| 147 | $this->session->set_userdata('user_header', $data['website_header']); |
||
| 148 | $this->session->set_userdata('user_footer', $data['website_footer']); |
||
| 149 | // echo $data['user_logo'];exit; |
||
| 150 | /***************************************************************************************/ |
||
| 151 | $this->session->set_userdata('user_login', FALSE); |
||
| 152 | $data['app_name'] = 'ASTPP - Open Source Billing Solution'; |
||
| 153 | $this->load->view('view_login', $data); |
||
| 154 | }else { |
||
| 155 | /* |
||
| 156 | * |
||
| 157 | * Purpose : Display logo based on domain name |
||
| 158 | * |
||
| 159 | */ |
||
| 160 | $this->db->select("*"); |
||
| 161 | $this->db->where(array("domain"=>$_SERVER["HTTP_HOST"])); |
||
| 162 | $res = $this->db->get("invoice_conf"); |
||
| 163 | $logo_arr = $res->result(); |
||
| 164 | //print_r( $logo_arr );exit; |
||
| 165 | |||
| 166 | $data['user_logo'] = (isset($logo_arr[0]->logo) && $logo_arr[0]->logo != "") ? $logo_arr[0]->accountid."_".$logo_arr[0]->logo : "logo.png"; |
||
| 167 | $data['user_header'] = (isset($logo_arr[0]->website_title) && $logo_arr[0]->website_title != "") ? $logo_arr[0]->website_title : "ASTPP - Open Source Voip Billing Solution"; |
||
| 168 | $data['user_footer'] = (isset($logo_arr[0]->website_footer) && $logo_arr[0]->website_footer != "") ? $logo_arr[0]->website_footer : "Inextrix Technologies Pvt. Ltd All Rights Reserved."; |
||
| 169 | |||
| 170 | $this->session->set_userdata('user_logo', $data['user_logo']); |
||
| 171 | $this->session->set_userdata('user_header', $data['user_header']); |
||
| 172 | $this->session->set_userdata('user_footer', $data['user_footer']); |
||
| 173 | // echo $data['user_logo'];exit; |
||
| 174 | /***************************************************************************************/ |
||
| 175 | if ($this->session->userdata('logintype') == '2') { |
||
| 176 | redirect(base_url() . 'dashboard/'); |
||
| 177 | } else { |
||
| 178 | redirect(base_url().'user/user/'); |
||
| 179 | } |
||
| 180 | } |
||
| 181 | } |
||
| 182 | |||
| 337 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.