| Conditions | 13 |
| Paths | 408 |
| Total Lines | 77 |
| Code Lines | 52 |
| Lines | 9 |
| Ratio | 11.69 % |
| 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 |
||
| 15 | public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null) |
||
|
|
|||
| 16 | { |
||
| 17 | $totalTransactions = array(); |
||
| 18 | |||
| 19 | // Don't need merchant list here |
||
| 20 | // $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList); |
||
| 21 | |||
| 22 | |||
| 23 | if (isset($_ENV['AFFILINET_CURRENCY'])) { |
||
| 24 | // 2018-04-16 - <PN> |
||
| 25 | $currency = $_ENV['AFFILINET_CURRENCY']; |
||
| 26 | } |
||
| 27 | else { |
||
| 28 | $currency = 'EUR'; |
||
| 29 | } |
||
| 30 | |||
| 31 | $step = 0; |
||
| 32 | |||
| 33 | try { |
||
| 34 | $publisherStatisticsServiceUrl = 'https://api.affili.net/V2.0/PublisherStatistics.svc?wsdl'; |
||
| 35 | $publisherStatisticsService = new \SoapClient($publisherStatisticsServiceUrl, array('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE, 'soap_version' => SOAP_1_1)); |
||
| 36 | |||
| 37 | // Handle two steps: 1^ to get registered transactions / 2^ to get confirmed or cancelled transactions - <PN> 2017-06-27 |
||
| 38 | while ($step++ <= 2) { |
||
| 39 | $params = array( |
||
| 40 | 'StartDate' => \strtotime($dStartDate->format("Y-m-d")), |
||
| 41 | 'EndDate' => \strtotime($dEndDate->format("Y-m-d")), |
||
| 42 | 'TransactionStatus' => 'All', |
||
| 43 | 'ValuationType' => $step == 1 ? 'DateOfRegistration' : 'DateOfConfirmation' |
||
| 44 | ); |
||
| 45 | $currentPage = 1; |
||
| 46 | $transactionList = self::affilinetCall('transaction', $publisherStatisticsService, $params, 0, $currentPage); |
||
| 47 | |||
| 48 | while (isset($transactionList->TotalRecords) && $transactionList->TotalRecords > 0 && isset($transactionList->TransactionCollection->Transaction)) { |
||
| 49 | $transactionCollection = array(); |
||
| 50 | if (!\is_array($transactionList->TransactionCollection->Transaction)) { |
||
| 51 | $transactionCollection[] = $transactionList->TransactionCollection->Transaction; |
||
| 52 | } else { |
||
| 53 | $transactionCollection = $transactionList->TransactionCollection->Transaction; |
||
| 54 | } |
||
| 55 | |||
| 56 | foreach ($transactionCollection as $transactionObject) { |
||
| 57 | |||
| 58 | $transaction = array(); |
||
| 59 | $transaction["status"] = $transactionObject->TransactionStatus; |
||
| 60 | $transaction["unique_id"] = $transactionObject->TransactionId; |
||
| 61 | $transaction["commission"] = $transactionObject->PublisherCommission; |
||
| 62 | $transaction["currency"] = $currency; // 2018-04-16 - <PN> |
||
| 63 | $transaction["amount"] = $transactionObject->NetPrice; |
||
| 64 | $transaction["date"] = $transactionObject->RegistrationDate; |
||
| 65 | $transaction["click_date"] = $transactionObject->ClickDate; // Future use - <PN> |
||
| 66 | $transaction["udpate_date"] = $transactionObject->CheckDate; // Future use - <PN> |
||
| 67 | $transaction["merchantId"] = $transactionObject->ProgramId; |
||
| 68 | $transaction["custom_id"] = $transactionObject->SubId; |
||
| 69 | View Code Duplication | if ($transaction['status'] == 'Confirmed') { |
|
| 70 | $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED; |
||
| 71 | } else |
||
| 72 | if ($transaction['status'] == 'Open') { |
||
| 73 | $transaction['status'] = \Oara\Utilities::STATUS_PENDING; |
||
| 74 | } else |
||
| 75 | if ($transaction['status'] == 'Cancelled') { |
||
| 76 | $transaction['status'] = \Oara\Utilities::STATUS_DECLINED; |
||
| 77 | } |
||
| 78 | $totalTransactions[] = $transaction; |
||
| 79 | } |
||
| 80 | $currentPage++; |
||
| 81 | $transactionList = self::affilinetCall('transaction', $publisherStatisticsService, $params, 0, $currentPage); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } catch (\Exception $e) { |
||
| 85 | // Avoid lost of transactions if one call failed |
||
| 86 | echo PHP_EOL . "AffilinetEx - getTransactionList err: ".$e->getMessage().PHP_EOL; |
||
| 87 | throw new \Exception($e); |
||
| 88 | } |
||
| 89 | echo (New \DateTime())->format("d/m/Y H:i:s") . " - AffilinetEx getTransactionList - return " . count($totalTransactions) . " transactions" . PHP_EOL; |
||
| 90 | return $totalTransactions; |
||
| 91 | } |
||
| 92 | } |
||
| 93 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: