Conditions | 12 |
Paths | 648 |
Total Lines | 67 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 1 |
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 |
||
59 | public function purchase() |
||
60 | { |
||
61 | $details = $this->invoice->getDetails(); |
||
62 | |||
63 | $name = ''; |
||
64 | if (!empty($details['name'])) { |
||
65 | $name = $details['name']; |
||
66 | } |
||
67 | |||
68 | $mobile = ''; |
||
69 | if (!empty($details['mobile'])) { |
||
70 | $mobile = $details['mobile']; |
||
71 | } elseif (!empty($details['phone'])) { |
||
72 | $mobile = $details['phone']; |
||
73 | } |
||
74 | |||
75 | $email = ''; |
||
76 | if (!empty($details['mail'])) { |
||
77 | $email = $details['mail']; |
||
78 | } elseif (!empty($details['email'])) { |
||
79 | $email = $details['email']; |
||
80 | } |
||
81 | |||
82 | $desc = ''; |
||
83 | if (!empty($details['desc'])) { |
||
84 | $desc = $details['desc']; |
||
85 | } elseif (!empty($details['description'])) { |
||
86 | $desc = $details['description']; |
||
87 | } |
||
88 | |||
89 | $amount = $this->invoice->getAmount(); |
||
90 | if ($this->settings->currency != 'T') { |
||
91 | $amount /= 10; |
||
92 | } |
||
93 | $amount = intval(ceil($amount)); |
||
94 | |||
95 | $orderId = crc32($this->invoice->getUuid()); |
||
96 | if (!empty($details['orderId'])) { |
||
97 | $orderId = $details['orderId']; |
||
98 | } elseif (!empty($details['order_id'])) { |
||
99 | $orderId = $details['order_id']; |
||
100 | } |
||
101 | |||
102 | $data = array( |
||
103 | "MerchantID" => $this->settings->merchantId, |
||
104 | "Amount" => $amount, |
||
105 | "InvoiceID" => $orderId, |
||
106 | "Description" => $desc, |
||
107 | "FullName" => $name, |
||
108 | "Email" => $email, |
||
109 | "Mobile" => $mobile, |
||
110 | "CallbackURL" => $this->settings->callbackUrl, |
||
111 | ); |
||
112 | |||
113 | $response = $this->client->request('POST', $this->settings->apiPurchaseUrl, ["json" => $data, "http_errors" => false]); |
||
114 | |||
115 | $body = json_decode($response->getBody()->getContents(), false); |
||
116 | |||
117 | if ($body->Status != 100) { |
||
118 | // some error has happened |
||
119 | throw new PurchaseFailedException($body->Message); |
||
120 | } |
||
121 | |||
122 | $this->invoice->transactionId($body->Authority); |
||
123 | |||
124 | // return the transaction's id |
||
125 | return $this->invoice->getTransactionId(); |
||
126 | } |
||
199 |