Conditions | 10 |
Paths | 15 |
Total Lines | 60 |
Lines | 7 |
Ratio | 11.67 % |
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 |
||
94 | public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null) |
||
95 | { |
||
96 | $totalTransactions = array(); |
||
97 | $auxDate = clone $dStartDate; |
||
98 | $amountDays = $dStartDate->diff($dEndDate)->days; |
||
99 | for ($j = 0; $j < $amountDays; $j++) { |
||
100 | |||
101 | // Getting the csv by curl can throw an exception if the csv size is 0 bytes. So, first of all, get the json. If total is 0, continue, else, get the csv. |
||
102 | $valuesFormExport = array(); |
||
103 | $url = "https://partner-int-api.groupon.com/reporting/v2/order.json?clientId={$this->_credentials['apipassword']}&group=order&date={$auxDate->format("Y-m-d")}"; |
||
104 | if (!empty($this->_countryIsoCode)) { |
||
105 | $url .= '&order.country=' . $this->_countryIsoCode; |
||
106 | } |
||
107 | $urls = array(); |
||
108 | $urls[] = new \Oara\Curl\Request($url, $valuesFormExport); |
||
109 | $exportReport = $this->_client->get($urls); |
||
110 | $jsonExportReport = json_decode($exportReport[0], true); |
||
111 | |||
112 | if ($jsonExportReport['total'] != 0) { |
||
113 | |||
114 | $valuesFormExport = array(); |
||
115 | $url = "https://partner-int-api.groupon.com/reporting/v2/order.csv?clientId={$this->_credentials['apipassword']}&group=order&date={$auxDate->format("Y-m-d")}"; |
||
116 | if (!empty($this->_countryIsoCode)) { |
||
117 | $url .= '&order.country=' . $this->_countryIsoCode; |
||
118 | } |
||
119 | $urls = array(); |
||
120 | $urls[] = new \Oara\Curl\Request($url, $valuesFormExport); |
||
121 | $exportReport = $this->_client->get($urls); |
||
122 | $exportData = \str_getcsv($exportReport[0], "\n"); |
||
123 | $num = \count($exportData); |
||
124 | for ($i = 1; $i < $num; $i++) { |
||
125 | $transactionExportArray = \str_getcsv($exportData[$i], ","); |
||
126 | $transaction = Array(); |
||
127 | $transaction['merchantId'] = "1"; |
||
128 | $transaction['date'] = $auxDate->format("Y-m-d H:i:s"); |
||
129 | $transaction['unique_id'] = $transactionExportArray[0]; |
||
130 | $transaction['currency'] = $transactionExportArray[4]; |
||
131 | |||
132 | if ($transactionExportArray[1] != null) { |
||
133 | $transaction['custom_id'] = $transactionExportArray[1]; |
||
134 | } |
||
135 | |||
136 | View Code Duplication | if ($transactionExportArray[5] == 'VALID') { |
|
137 | $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED; |
||
138 | } else if ($transactionExportArray[5] == 'INVALID' || $transactionExportArray[5] == 'REFUNDED') { |
||
139 | $transaction['status'] = \Oara\Utilities::STATUS_DECLINED; |
||
140 | } else { |
||
141 | throw new \Exception("Status {$transactionExportArray[5]} unknown"); |
||
142 | } |
||
143 | |||
144 | $transaction['amount'] = \Oara\Utilities::parseDouble((double)$transactionExportArray[8]); |
||
145 | $transaction['commission'] = \Oara\Utilities::parseDouble((double)$transactionExportArray[12]); |
||
146 | $totalTransactions[] = $transaction; |
||
147 | } |
||
148 | } |
||
149 | $auxDate->add(new \DateInterval('P1D')); |
||
150 | } |
||
151 | |||
152 | return $totalTransactions; |
||
153 | } |
||
154 | |||
156 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: