Conditions | 13 |
Paths | 11 |
Total Lines | 42 |
Code Lines | 21 |
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 |
||
89 | public function getPaymentStatus($orderId, $paymentId, $KeyType = 'PaymentId') { |
||
90 | $res = $this->getMessage(); |
||
91 | $json = json_decode($res); |
||
92 | if ($orderId && $json->Data->CustomerReference != $orderId) { |
||
93 | return 'Trying to call data of another order'; |
||
94 | } else if ($json->Data->InvoiceStatus == 'DuplicatePayment') { |
||
95 | return 'Duplicate Payment'; //success with Duplicate |
||
96 | } |
||
97 | |||
98 | if ($KeyType == 'PaymentId') { |
||
99 | foreach ($json->Data->InvoiceTransactions as $transaction) { |
||
100 | if ($transaction->PaymentId == $paymentId && $transaction->Error && $json->Data->InvoiceStatus != 'Paid') { |
||
101 | return 'Failed with Error (' . $transaction->Error . ')'; //faild order |
||
102 | } |
||
103 | } |
||
104 | } |
||
105 | if ($json->Data->InvoiceStatus != 'Paid') { |
||
106 | //------------------ |
||
107 | //case 1: |
||
108 | $lastInvoiceTransactions = end($json->Data->InvoiceTransactions); |
||
109 | if ($lastInvoiceTransactions && $lastInvoiceTransactions->Error) { |
||
110 | return 'Failed with Error (' . $lastInvoiceTransactions->Error . ')'; //faild order |
||
111 | } |
||
112 | |||
113 | //------------------ |
||
114 | //case 2: |
||
115 | //all myfatoorah gateway is set to Asia/Kuwait |
||
116 | $ExpiryDate = new \DateTime($json->Data->ExpiryDate, new \DateTimeZone('Asia/Kuwait')); |
||
117 | $ExpiryDate->modify('+1 day'); ///????????????$ExpiryDate without any hour so for i added the 1 day just in case. this should be changed after adding the tome to the expire date |
||
118 | $currentDate = new \DateTime('now', new \DateTimeZone('Asia/Kuwait')); |
||
119 | |||
120 | if ($ExpiryDate < $currentDate) { |
||
121 | return'Invoice is expired since: ' . $ExpiryDate->format('Y-m-d'); //cancelled order |
||
122 | } |
||
123 | |||
124 | //------------------ |
||
125 | //case 3: |
||
126 | //payment is pending .. user has not paid yet and the invoice is not expired |
||
127 | return 'Payment is pending'; |
||
128 | } |
||
129 | |||
130 | return print_r($json->Data, 1); |
||
131 | } |
||
138 |