| Conditions | 19 |
| Paths | 282 |
| Total Lines | 141 |
| Code Lines | 112 |
| 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 |
||
| 11 | public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null) |
||
| 12 | { |
||
| 13 | $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList); |
||
| 14 | |||
| 15 | $totalTransactions = Array(); |
||
| 16 | $valuesFormExport = array(new \Oara\Curl\Parameter('reportName', 'aAffiliateEventBreakdownReport'), |
||
| 17 | new \Oara\Curl\Parameter('columns', 'programId'), |
||
| 18 | new \Oara\Curl\Parameter('columns', 'timeOfVisit'), |
||
| 19 | new \Oara\Curl\Parameter('columns', 'timeOfEvent'), |
||
| 20 | new \Oara\Curl\Parameter('columns', 'timeInSession'), |
||
| 21 | new \Oara\Curl\Parameter('columns', 'lastModified'), |
||
| 22 | new \Oara\Curl\Parameter('columns', 'epi1'), |
||
| 23 | new \Oara\Curl\Parameter('columns', 'eventName'), |
||
| 24 | new \Oara\Curl\Parameter('columns', 'pendingStatus'), |
||
| 25 | new \Oara\Curl\Parameter('columns', 'siteName'), |
||
| 26 | new \Oara\Curl\Parameter('columns', 'graphicalElementName'), |
||
| 27 | new \Oara\Curl\Parameter('columns', 'graphicalElementId'), |
||
| 28 | new \Oara\Curl\Parameter('columns', 'productName'), |
||
| 29 | new \Oara\Curl\Parameter('columns', 'productNrOf'), |
||
| 30 | new \Oara\Curl\Parameter('columns', 'productValue'), |
||
| 31 | new \Oara\Curl\Parameter('columns', 'affiliateCommission'), |
||
| 32 | new \Oara\Curl\Parameter('columns', 'link'), |
||
| 33 | new \Oara\Curl\Parameter('columns', 'leadNR'), |
||
| 34 | new \Oara\Curl\Parameter('columns', 'orderNR'), |
||
| 35 | new \Oara\Curl\Parameter('columns', 'pendingReason'), |
||
| 36 | new \Oara\Curl\Parameter('columns', 'orderValue'), |
||
| 37 | new \Oara\Curl\Parameter('isPostBack', ''), |
||
| 38 | new \Oara\Curl\Parameter('metric1.lastOperator', '/'), |
||
| 39 | new \Oara\Curl\Parameter('interval', ''), |
||
| 40 | new \Oara\Curl\Parameter('favoriteDescription', ''), |
||
| 41 | new \Oara\Curl\Parameter('event_id', '0'), |
||
| 42 | new \Oara\Curl\Parameter('pending_status', '1'), |
||
| 43 | new \Oara\Curl\Parameter('run_as_organization_id', ''), |
||
| 44 | new \Oara\Curl\Parameter('minRelativeIntervalStartTime', '0'), |
||
| 45 | new \Oara\Curl\Parameter('includeWarningColumn', 'true'), |
||
| 46 | new \Oara\Curl\Parameter('metric1.summaryType', 'NONE'), |
||
| 47 | new \Oara\Curl\Parameter('metric1.operator1', '/'), |
||
| 48 | new \Oara\Curl\Parameter('latestDayToExecute', '0'), |
||
| 49 | new \Oara\Curl\Parameter('showAdvanced', 'true'), |
||
| 50 | new \Oara\Curl\Parameter('breakdownOption', '1'), |
||
| 51 | new \Oara\Curl\Parameter('metric1.midFactor', ''), |
||
| 52 | new \Oara\Curl\Parameter('reportTitleTextKey', 'REPORT3_SERVICE_REPORTS_AAFFILIATEEVENTBREAKDOWNREPORT_TITLE'), |
||
| 53 | new \Oara\Curl\Parameter('setColumns', 'true'), |
||
| 54 | new \Oara\Curl\Parameter('metric1.columnName1', 'orderValue'), |
||
| 55 | new \Oara\Curl\Parameter('metric1.columnName2', 'orderValue'), |
||
| 56 | new \Oara\Curl\Parameter('reportPrograms', ''), |
||
| 57 | new \Oara\Curl\Parameter('metric1.midOperator', '/'), |
||
| 58 | new \Oara\Curl\Parameter('dateSelectionType', '2'), |
||
| 59 | new \Oara\Curl\Parameter('favoriteName', ''), |
||
| 60 | new \Oara\Curl\Parameter('affiliateId', ''), |
||
| 61 | new \Oara\Curl\Parameter('dateType', '1'), |
||
| 62 | new \Oara\Curl\Parameter('period', 'custom_period'), |
||
| 63 | new \Oara\Curl\Parameter('tabMenuName', ''), |
||
| 64 | new \Oara\Curl\Parameter('maxIntervalSize', '0'), |
||
| 65 | new \Oara\Curl\Parameter('favoriteId', ''), |
||
| 66 | new \Oara\Curl\Parameter('sortBy', 'timeOfEvent'), |
||
| 67 | new \Oara\Curl\Parameter('metric1.name', ''), |
||
| 68 | new \Oara\Curl\Parameter('customKeyMetricCount', '0'), |
||
| 69 | new \Oara\Curl\Parameter('metric1.factor', ''), |
||
| 70 | new \Oara\Curl\Parameter('showFavorite', 'false'), |
||
| 71 | new \Oara\Curl\Parameter('separator', ','), |
||
| 72 | new \Oara\Curl\Parameter('format', 'CSV') |
||
| 73 | ); |
||
| 74 | $valuesFormExport[] = new \Oara\Curl\Parameter('startDate', self::formatDate($dStartDate)); |
||
| 75 | $valuesFormExport[] = new \Oara\Curl\Parameter('endDate', self::formatDate($dEndDate)); |
||
| 76 | $urls = array(); |
||
| 77 | $urls[] = new \Oara\Curl\Request('http://publisher.tradedoubler.com/pan/aReport3Internal.action?', $valuesFormExport); |
||
| 78 | $exportReport = $this->_client->get($urls); |
||
| 79 | |||
| 80 | $exportReport[0] = self::checkReportError($exportReport[0], $urls[0]); |
||
| 81 | $exportData = \str_getcsv($exportReport[0], "\r\n"); |
||
| 82 | $num = \count($exportData); |
||
| 83 | for ($i = 2; $i < $num - 1; $i++) { |
||
| 84 | |||
| 85 | $transactionExportArray = \str_getcsv($exportData[$i], ","); |
||
| 86 | |||
| 87 | if (!isset($transactionExportArray[2])) { |
||
| 88 | throw new \Exception('Problem getting transaction\n\n'); |
||
| 89 | } |
||
| 90 | if (\count($this->_sitesAllowed) == 0 || \in_array($transactionExportArray[13], $this->_sitesAllowed)) { |
||
| 91 | |||
| 92 | |||
| 93 | if ($transactionExportArray[0] !== '' && isset($merchantIdList[(int)$transactionExportArray[2]])) { |
||
| 94 | |||
| 95 | $transaction = Array(); |
||
| 96 | $transaction['merchantId'] = $transactionExportArray[2]; |
||
| 97 | $transactionDate = self::toDate(\substr($transactionExportArray[4], 0, -6)); |
||
| 98 | |||
| 99 | $transaction['date'] = $transactionDate->format("Y-m-d H:i:s"); |
||
| 100 | if ($transactionExportArray[8] != '') { |
||
| 101 | $transaction['unique_id'] = \substr($transactionExportArray[8], 0, 200); |
||
| 102 | } else |
||
| 103 | if ($transactionExportArray[7] != '') { |
||
| 104 | $transaction['unique_id'] = \substr($transactionExportArray[7], 0, 200); |
||
| 105 | } else { |
||
| 106 | throw new \Exception("No Identifier"); |
||
| 107 | } |
||
| 108 | |||
| 109 | |||
| 110 | if ($transactionExportArray[9] != '') { |
||
| 111 | $transaction['custom_id'] = $transactionExportArray[9]; |
||
| 112 | } |
||
| 113 | |||
| 114 | if ($transactionExportArray[11] == 'A') { |
||
| 115 | $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED; |
||
| 116 | } else |
||
| 117 | if ($transactionExportArray[11] == 'P') { |
||
| 118 | $transaction['status'] = \Oara\Utilities::STATUS_PENDING; |
||
| 119 | } else |
||
| 120 | if ($transactionExportArray[11] == 'D') { |
||
| 121 | $transaction['status'] = \Oara\Utilities::STATUS_DECLINED; |
||
| 122 | } |
||
| 123 | |||
| 124 | if ($transactionExportArray[19] != '') { |
||
| 125 | $transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray[19]); |
||
| 126 | } else { |
||
| 127 | $transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray[20]); |
||
| 128 | } |
||
| 129 | |||
| 130 | $transaction['commission'] = \Oara\Utilities::parseDouble($transactionExportArray[20]); |
||
| 131 | $totalTransactions[] = $transaction; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | } |
||
| 135 | $insertedTransactions=parent::getTransactionList($merchantList,$dStartDate,$dEndDate); |
||
| 136 | foreach ($insertedTransactions as $transaction){ |
||
| 137 | if (array_key_exists('unique_id',$transaction)){ |
||
| 138 | $found=false; |
||
| 139 | foreach ($totalTransactions as $transaction2){ |
||
| 140 | if ($transaction2['unique_id']==$transaction['unique_id']){ |
||
| 141 | $found=true; |
||
| 142 | break; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | if (!$found){ |
||
| 146 | $totalTransactions[]=$transaction; |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } |
||
| 150 | return $totalTransactions; |
||
| 151 | } |
||
| 152 | } |