Conditions | 8 |
Paths | 6 |
Total Lines | 69 |
Code Lines | 50 |
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 |
||
31 | public function processPayment($data, $form) |
||
32 | { |
||
33 | //get variables |
||
34 | $this->retrieveVariables(); |
||
35 | if ( |
||
36 | $this->_processing_member && |
||
37 | $this->_processing_member->CreditCardHasBeenRecorded() |
||
38 | ) { |
||
39 | //save basic info |
||
40 | //no idea why we need this!!! |
||
41 | if ($this->_processing_amount) { |
||
42 | $this->Amount->Amount = $this->_processing_amount / 100; |
||
43 | } |
||
44 | $this->Status = "Pending"; |
||
45 | $returnObject = EcommercePayment_Success::create(); |
||
46 | } else { |
||
47 | $billingAddress = $this->_processing_order->CreateOrReturnExistingAddress("BillingAddress"); |
||
48 | $this->instantiateAPI(); |
||
49 | //first create the customer |
||
50 | $requestData = array( |
||
51 | "description" => $this->_processing_statement_description, |
||
52 | "metadata" => $this->_processing_metadata, |
||
53 | "email" => $billingAddress->Email, |
||
54 | "source" => array( |
||
55 | "object" => "card", |
||
56 | "exp_month" => $this->_processing_card['exp_month'], |
||
57 | "exp_year" => $this->_processing_card['exp_year'], |
||
58 | "number" => $this->_processing_card['number'], |
||
59 | "name" => $this->_processing_card['name'], |
||
60 | "address_line1" => $billingAddress->Address, |
||
61 | "address_line2" => $billingAddress->Address2, |
||
62 | "address_state" => $billingAddress->RegionCode, |
||
63 | "address_city" => $billingAddress->City, |
||
64 | "address_zip" => $billingAddress->PostalCode, |
||
65 | "address_country" => $billingAddress->RegionCode |
||
66 | ) |
||
67 | ); |
||
68 | |||
69 | $responseData = \Stripe\Customer::create( |
||
70 | $requestData, |
||
71 | $this->_processing_idempotency_key |
||
72 | ); |
||
73 | $this->removeCardDetails(); |
||
74 | $requestData["card"]["number"] = $this->_processing_truncated_card; |
||
75 | $this->recordTransaction($requestData, $responseData); |
||
76 | |||
77 | //save basic info |
||
78 | //no idea why we need this!!! |
||
79 | if ($this->_processing_amount) { |
||
80 | $this->Amount->Amount = $this->_processing_amount / 100; |
||
81 | } |
||
82 | if ( |
||
83 | $responseData && |
||
84 | isset($responseData->id) && |
||
85 | $this->_processing_member instanceof Member |
||
86 | ) { |
||
87 | $this->Status = "Pending"; |
||
88 | $this->_processing_member->StripeCustomerID = $responseData->id; |
||
89 | $this->_processing_member->CreditCardDescription = $this->_processing_card_description; |
||
90 | $this->_processing_member->write(); |
||
91 | $returnObject = EcommercePayment_Success::create(); |
||
92 | } else { |
||
93 | $this->Status = "Failure"; |
||
94 | $returnObject = EcommercePayment_Failure::create(); |
||
95 | } |
||
96 | } |
||
97 | $this->write(); |
||
98 | return $returnObject; |
||
99 | } |
||
100 | |||
143 |
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.