| Conditions | 17 |
| Paths | 98 |
| Total Lines | 130 |
| Code Lines | 118 |
| 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 |
||
| 187 | function paypal_response(){ |
||
| 188 | if(count($_POST)>0) |
||
| 189 | { |
||
| 190 | $response_arr=$_POST; |
||
| 191 | $fp=fopen("/var/log/astpp/astpp_payment.log","w+"); |
||
| 192 | $date = date("Y-m-d H:i:s"); |
||
| 193 | fwrite($fp,"====================".$date."===============================\n"); |
||
| 194 | foreach($response_arr as $key => $value){ |
||
| 195 | fwrite($fp,$key.":::>".$value."\n"); |
||
| 196 | } |
||
| 197 | $payment_check = $this->db_model->countQuery("txn_id", "payments", array("txn_id" => $response_arr['txn_id'])); |
||
| 198 | if( ($response_arr["payment_status"] == "Pending" || $response_arr["payment_status"] == "Complete" || $response_arr["payment_status"] == "Completed" ) && $payment_check == 0){ |
||
| 199 | |||
| 200 | $paypal_tax = (array)$this->db->get_where("system", array("name" => "paypal_tax","group_title"=>"paypal"))->first_row(); |
||
| 201 | $paypal_tax =$paypal_tax['value']; |
||
| 202 | $balance_amt = $actual_amount = $response_arr["custom"]; |
||
| 203 | $paypal_fee = (array)$this->db->get_where("system", array("name" => "paypal_fee","group_title"=>"paypal"))->first_row(); |
||
| 204 | $paypal_fee = $paypal_fee['value']; |
||
| 205 | $paypalfee = ($paypal_fee == 0)?'0':$response_arr["mc_gross"]; |
||
| 206 | $account_data = (array)$this->db->get_where("accounts", array("id" => $response_arr["item_number"]))->first_row(); |
||
| 207 | $currency = (array)$this->db->get_where('currency', array("id"=>$account_data["currency_id"]))->first_row(); |
||
| 208 | $date = date('Y-m-d H:i:s'); |
||
| 209 | $payment_trans_array = array("accountid"=>$response_arr["item_number"], |
||
| 210 | "amount"=>$response_arr["payment_gross"], |
||
| 211 | "tax"=>"1", |
||
| 212 | "payment_method"=>"Paypal", |
||
| 213 | "actual_amount"=>$actual_amount, |
||
| 214 | "paypal_fee"=>$paypalfee, |
||
| 215 | "user_currency"=>$currency["currency"], |
||
| 216 | "currency_rate"=>$currency["currencyrate"], |
||
| 217 | "transaction_details"=>json_encode($response_arr), |
||
| 218 | "date"=>$date); |
||
| 219 | $paymentid=$this->db->insert('payment_transaction',$payment_trans_array); |
||
| 220 | $parent_id =$account_data['reseller_id'] > 0 ? $account_data['reseller_id'] : '-1'; |
||
| 221 | $payment_arr = array("accountid"=> $response_arr["item_number"], |
||
| 222 | "payment_mode"=>"1","credit"=>$balance_amt, |
||
| 223 | "type"=>"PAYPAL", |
||
| 224 | "payment_by"=>$parent_id, |
||
| 225 | "notes"=>"Payment Made by Paypal on date:-".$date, |
||
| 226 | "paypalid"=>$paymentid, |
||
| 227 | "txn_id"=>$response_arr["txn_id"], |
||
| 228 | 'payment_date'=>gmdate('Y-m-d H:i:s',strtotime($response_arr['payment_date']))); |
||
| 229 | $this->db->insert('payments', $payment_arr); |
||
| 230 | $this->db->select('invoiceid'); |
||
| 231 | $this->db->order_by('id','desc'); |
||
| 232 | $this->db->limit(1); |
||
| 233 | $last_invoice_result=(array)$this->db->get('invoices')->first_row(); |
||
| 234 | $last_invoice_ID=isset($last_invoice_result['invoiceid'] ) && $last_invoice_result['invoiceid'] > 0 ?$last_invoice_result['invoiceid'] : 1; |
||
| 235 | $reseller_id=$account_data['reseller_id'] > 0 ? $account_data['reseller_id'] : 0; |
||
| 236 | $where="accountid IN ('".$reseller_id."','1')"; |
||
| 237 | $this->db->where($where); |
||
| 238 | $this->db->select('*'); |
||
| 239 | $this->db->order_by('accountid', 'desc'); |
||
| 240 | $this->db->limit(1); |
||
| 241 | $invoiceconf = $this->db->get('invoice_conf'); |
||
| 242 | $invoiceconf = (array)$invoiceconf->first_row(); |
||
| 243 | $invoice_prefix=$invoiceconf['invoice_prefix']; |
||
| 244 | |||
| 245 | $due_date = gmdate("Y-m-d H:i:s",strtotime(gmdate("Y-m-d H:i:s")." +".$invoiceconf['interval']." days")); |
||
| 246 | $invoice_id=$this->generate_receipt($account_data['id'],$balance_amt,$account_data,$last_invoice_ID+1,$invoice_prefix,$due_date); |
||
| 247 | $details_insert=array( |
||
| 248 | 'created_date'=>$date, |
||
| 249 | 'credit'=>$balance_amt, |
||
| 250 | 'debit'=>'-', |
||
| 251 | 'accountid'=>$account_data["id"], |
||
| 252 | 'reseller_id'=>$account_data['reseller_id'], |
||
| 253 | 'invoiceid'=>$invoice_id, |
||
| 254 | 'description'=>"Payment Made by Paypal on date:-".$date, |
||
| 255 | 'item_type'=>'PAYMENT', |
||
| 256 | 'before_balance'=>$account_data['balance'], |
||
| 257 | 'after_balance'=>$account_data['balance']+$balance_amt, |
||
| 258 | ); |
||
| 259 | $this->db->insert("invoice_details", $details_insert); |
||
| 260 | $this->db_model->update_balance($balance_amt,$account_data["id"],"credit"); |
||
| 261 | if($parent_id > 0){ |
||
| 262 | $reseller_ids=$this->common->get_parent_info($parent_id,0); |
||
| 263 | $reseller_ids=rtrim($reseller_ids,","); |
||
| 264 | $reseller_arr=explode(",",$reseller_ids); |
||
| 265 | if(!empty($reseller_arr)){ |
||
| 266 | foreach($reseller_arr as $key=>$reseller_id){ |
||
| 267 | $account_data = (array)$this->db->get_where("accounts", array("id" => $reseller_id))->first_row(); |
||
| 268 | $this->db->select('invoiceid'); |
||
| 269 | $this->db->order_by('id','desc'); |
||
| 270 | $this->db->limit(1); |
||
| 271 | $last_invoice_result=(array)$this->db->get('invoices')->first_row(); |
||
| 272 | $last_invoice_ID=$last_invoice_result['invoiceid']; |
||
| 273 | $reseller_id=$account_data['reseller_id'] > 0 ? $account_data['reseller_id'] : 0; |
||
| 274 | $where="accountid IN ('".$reseller_id."','1')"; |
||
| 275 | $this->db->where($where); |
||
| 276 | $this->db->select('*'); |
||
| 277 | $this->db->order_by('accountid', 'desc'); |
||
| 278 | $this->db->limit(1); |
||
| 279 | $invoiceconf = $this->db->get('invoice_conf'); |
||
| 280 | $invoiceconf = (array)$invoiceconf->first_row(); |
||
| 281 | $invoice_prefix=$invoiceconf['invoice_prefix']; |
||
| 282 | $due_date = gmdate("Y-m-d H:i:s",strtotime(gmdate("Y-m-d H:i:s")." +".$invoiceconf['interval']." days")); |
||
| 283 | $invoice_id=$this->generate_receipt($account_data['id'],$balance_amt,$account_data,$last_invoice_ID+1,$invoice_prefix,$due_date); |
||
| 284 | $parent_id=$account_data['reseller_id'] > 0 ? $account_data['reseller_id'] : -1; |
||
| 285 | $payment_arr = array("accountid"=> $account_data["id"], |
||
| 286 | "payment_mode"=>"1", |
||
| 287 | "credit"=>$balance_amt, |
||
| 288 | "type"=>"PAYPAL", |
||
| 289 | "payment_by"=>$parent_id, |
||
| 290 | "notes"=>"Your account has been credited due to your customer account recharge done by paypal", |
||
| 291 | "paypalid"=>$paymentid, |
||
| 292 | "txn_id"=>$response_arr["txn_id"], |
||
| 293 | 'payment_date'=>gmdate('Y-m-d H:i:s',strtotime($response_arr['payment_date']))); |
||
| 294 | $this->db->insert('payments', $payment_arr); |
||
| 295 | $details_insert=array( |
||
| 296 | 'created_date'=>$date, |
||
| 297 | 'credit'=>$balance_amt, |
||
| 298 | 'debit'=>'-', |
||
| 299 | 'accountid'=>$account_data['id'], |
||
| 300 | 'reseller_id'=>$parent_id, |
||
| 301 | 'invoiceid'=>$invoice_id, |
||
| 302 | 'description'=>"Your account has been credited due to your customer account recharge done by paypal", |
||
| 303 | 'item_type'=>'PAYMENT', |
||
| 304 | 'before_balance'=>$account_data['balance'], |
||
| 305 | 'after_balance'=>$account_data['balance']+$balance_amt, |
||
| 306 | ); |
||
| 307 | $this->db->insert("invoice_details", $details_insert); |
||
| 308 | $this->db_model->update_balance($balance_amt,$account_data["id"],"credit"); |
||
| 309 | } |
||
| 310 | } |
||
| 311 | } |
||
| 312 | redirect(base_url() . 'user/user/'); |
||
| 313 | } |
||
| 314 | } |
||
| 315 | redirect(base_url() . 'user/user/'); |
||
| 316 | } |
||
| 317 | |||
| 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.