Conditions | 15 |
Paths | 880 |
Total Lines | 86 |
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 | $totalTransactions = array(); |
||
18 | |||
19 | // Don't need merchant list here |
||
20 | // $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList); |
||
21 | $now = new \DateTime(); |
||
22 | |||
23 | if ($dEndDate->format('Y-m-d') == $now->format('Y-m-d')) { |
||
24 | // Ends Today ... set current hour |
||
25 | $dEndDate->setTime($now->format('h'), 0,0); |
||
|
|||
26 | } |
||
27 | else { |
||
28 | // End date in the past |
||
29 | $dEndDate->setTime(23,59,59); |
||
30 | } |
||
31 | |||
32 | if (isset($_ENV['AFFILINET_CURRENCY'])) { |
||
33 | // 2018-04-16 - <PN> |
||
34 | $currency = $_ENV['AFFILINET_CURRENCY']; |
||
35 | } |
||
36 | else { |
||
37 | $currency = 'EUR'; |
||
38 | } |
||
39 | |||
40 | $step = 0; |
||
41 | |||
42 | try { |
||
43 | $publisherStatisticsServiceUrl = 'https://api.affili.net/V2.0/PublisherStatistics.svc?wsdl'; |
||
44 | $publisherStatisticsService = new \SoapClient($publisherStatisticsServiceUrl, array('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE, 'soap_version' => SOAP_1_1)); |
||
45 | |||
46 | // Handle two steps: 1^ to get registered transactions / 2^ to get confirmed or cancelled transactions - <PN> 2017-06-27 |
||
47 | while ($step++ <= 2) { |
||
48 | $params = array( |
||
49 | 'StartDate' => \strtotime($dStartDate->format("Y-m-d 00:00:00")), |
||
50 | 'EndDate' => \strtotime($dEndDate->format("Y-m-d h:i:s")), |
||
51 | 'TransactionStatus' => 'All', |
||
52 | 'ValuationType' => $step == 1 ? 'DateOfRegistration' : 'DateOfConfirmation' |
||
53 | ); |
||
54 | $currentPage = 1; |
||
55 | $transactionList = self::affilinetCall('transaction', $publisherStatisticsService, $params, 0, $currentPage); |
||
56 | |||
57 | while (isset($transactionList->TotalRecords) && $transactionList->TotalRecords > 0 && isset($transactionList->TransactionCollection->Transaction)) { |
||
58 | $transactionCollection = array(); |
||
59 | if (!\is_array($transactionList->TransactionCollection->Transaction)) { |
||
60 | $transactionCollection[] = $transactionList->TransactionCollection->Transaction; |
||
61 | } else { |
||
62 | $transactionCollection = $transactionList->TransactionCollection->Transaction; |
||
63 | } |
||
64 | |||
65 | foreach ($transactionCollection as $transactionObject) { |
||
66 | $uniqueId = $transactionObject->TransactionId; |
||
67 | if (!isset($totalTransactions[$uniqueId])) { |
||
68 | $transaction = array(); |
||
69 | $transaction["status"] = $transactionObject->TransactionStatus; |
||
70 | $transaction["unique_id"] = $transactionObject->TransactionId; |
||
71 | $transaction["commission"] = $transactionObject->PublisherCommission; |
||
72 | $transaction["currency"] = $currency; // 2018-04-16 - <PN> |
||
73 | $transaction["amount"] = $transactionObject->NetPrice; |
||
74 | $transaction["date"] = $transactionObject->RegistrationDate; |
||
75 | $transaction["click_date"] = $transactionObject->ClickDate; // Future use - <PN> |
||
76 | $transaction["udpate_date"] = $transactionObject->CheckDate; // Future use - <PN> |
||
77 | $transaction["merchantId"] = $transactionObject->ProgramId; |
||
78 | $transaction["custom_id"] = $transactionObject->SubId; |
||
79 | if ($transaction['status'] == 'Confirmed') { |
||
80 | $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED; |
||
81 | } elseif ($transaction['status'] == 'Open') { |
||
82 | $transaction['status'] = \Oara\Utilities::STATUS_PENDING; |
||
83 | } elseif ($transaction['status'] == 'Cancelled') { |
||
84 | $transaction['status'] = \Oara\Utilities::STATUS_DECLINED; |
||
85 | } |
||
86 | $totalTransactions[$uniqueId] = $transaction; |
||
87 | } |
||
88 | } |
||
89 | $currentPage++; |
||
90 | $transactionList = self::affilinetCall('transaction', $publisherStatisticsService, $params, 0, $currentPage); |
||
91 | } |
||
92 | } |
||
93 | } catch (\Exception $e) { |
||
94 | // Avoid lost of transactions if one call failed |
||
95 | echo PHP_EOL . "AffilinetEx - getTransactionList err: ".$e->getMessage().PHP_EOL; |
||
96 | throw new \Exception($e); |
||
97 | } |
||
98 | echo (New \DateTime())->format("d/m/Y H:i:s") . " - AffilinetEx getTransactionList - return " . count($totalTransactions) . " transactions" . PHP_EOL; |
||
99 | return $totalTransactions; |
||
100 | } |
||
101 | } |
||
102 |
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: