| Conditions | 8 |
| Paths | 87 |
| Total Lines | 78 |
| 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 |
||
| 15 | public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null) |
||
| 16 | { |
||
| 17 | try { |
||
| 18 | |||
| 19 | $totalTransactions = array(); |
||
| 20 | |||
| 21 | $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList); |
||
|
|
|||
| 22 | |||
| 23 | // Retrieve by date transaction instead of date click (type=datetran)- <PN> 2017-07-05 |
||
| 24 | // Fixed endpoint to apiv2.effiliation.com <PN> 2020-08-12 |
||
| 25 | $url = 'https://apiv2.effiliation.com/apiv2/transaction.csv?key=' . $this->_credentials["apiPassword"] . '&start=' . $dStartDate->format("d/m/Y") . '&end=' . $dEndDate->format("d/m/Y") . '&type=datetran&all=yes×tamp=' . time(); |
||
| 26 | // Set timeout to 300 secs. due to api delays - <PN> 2017-06-20 |
||
| 27 | $ctx = stream_context_create(array( |
||
| 28 | 'http' => array( |
||
| 29 | 'timeout' => 300 |
||
| 30 | ) |
||
| 31 | ) |
||
| 32 | ); |
||
| 33 | // Log Debug info |
||
| 34 | echo (New \DateTime())->format("d/m/Y H:i:s") . " - EffiliationEx getTransactionList from " . $dStartDate->format("d/m/Y") . " to " . $dEndDate->format("d/m/Y"),PHP_EOL; |
||
| 35 | |||
| 36 | $content = \utf8_encode(\file_get_contents($url, 0, $ctx)); |
||
| 37 | $exportData = \str_getcsv($content, "\n"); |
||
| 38 | $num = \count($exportData); |
||
| 39 | |||
| 40 | for ($i = 1; $i < $num; $i++) { |
||
| 41 | $transactionExportArray = \str_getcsv($exportData[$i], "|"); |
||
| 42 | // We don't need to check whether the merchant id is valid or not ... |
||
| 43 | // ... for old transactions may be expired and not included in current merchant list |
||
| 44 | // <PN> 2017-06-22 |
||
| 45 | // if (isset($merchantIdList[(int)$transactionExportArray[2]])) { |
||
| 46 | |||
| 47 | $transaction = Array(); |
||
| 48 | $merchantId = (int)$transactionExportArray[2]; |
||
| 49 | $transaction['merchantId'] = $merchantId; |
||
| 50 | // Changed Transaction date index from 10 to 12 - 2018-01-01 <PN> |
||
| 51 | $transaction['date'] = $transactionExportArray[12]; |
||
| 52 | $transaction["click_date"] = $transactionExportArray[11]; // Added <PN> |
||
| 53 | $transaction['unique_id'] = $transactionExportArray[0]; |
||
| 54 | $transaction['custom_id'] = ''; |
||
| 55 | $transaction['status'] = \Oara\Utilities::STATUS_PENDING; |
||
| 56 | if ($transactionExportArray[4] != null) { |
||
| 57 | $transaction['custom_id'] = $transactionExportArray[4]; |
||
| 58 | } |
||
| 59 | |||
| 60 | switch ($transactionExportArray[9]) { |
||
| 61 | case 'Valide': |
||
| 62 | $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED; |
||
| 63 | break; |
||
| 64 | case 'Attente': |
||
| 65 | $transaction['status'] = \Oara\Utilities::STATUS_PENDING; |
||
| 66 | break; |
||
| 67 | case 'Refusé': |
||
| 68 | case 'Refuse': |
||
| 69 | // Handle both variations - <PN> - 2017-06-21 |
||
| 70 | $transaction['status'] = \Oara\Utilities::STATUS_DECLINED; |
||
| 71 | break; |
||
| 72 | default: |
||
| 73 | // Invalid status |
||
| 74 | echo PHP_EOL."EffiliationEx - Invalid transaction status: " . $transactionExportArray[9] . " (transaction id = " . $transactionExportArray[0] . ")"; |
||
| 75 | break; |
||
| 76 | } |
||
| 77 | $transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray[7]); |
||
| 78 | $transaction['commission'] = \Oara\Utilities::parseDouble($transactionExportArray[8]); |
||
| 79 | // Get absolute values - 2017-12-13 <PN> |
||
| 80 | $transaction ['amount'] = \abs($transaction ['amount']); |
||
| 81 | $transaction ['commission'] = \abs($transaction ['commission']); |
||
| 82 | $totalTransactions[] = $transaction; |
||
| 83 | // } |
||
| 84 | } |
||
| 85 | } catch (\Exception $e) { |
||
| 86 | // Avoid lost of transactions if one date failed - <PN> - 2017-06-20 |
||
| 87 | echo PHP_EOL."EffiliationEx - getTransactionList err: ".$e->getMessage().PHP_EOL; |
||
| 88 | throw new \Exception($e); |
||
| 89 | } |
||
| 90 | echo (New \DateTime())->format("d/m/Y H:i:s") . " - EffiliationEx getTransactionList - return " . count($totalTransactions) . " transactions" . PHP_EOL; |
||
| 91 | return $totalTransactions; |
||
| 92 | } |
||
| 93 | } |
||
| 94 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.