Conditions | 7 |
Paths | 12 |
Total Lines | 68 |
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 |
||
112 | public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null) |
||
113 | { |
||
114 | $totalTransactions = array(); |
||
115 | |||
116 | $urls = array(); |
||
117 | |||
118 | $postParams = array( |
||
119 | new \Oara\Curl\Parameter('username', $this->_credentials['user']), |
||
120 | new \Oara\Curl\Parameter('password', $this->_credentials['password']), |
||
121 | new \Oara\Curl\Parameter('isEnc', 'false'), |
||
122 | new \Oara\Curl\Parameter('fileFormat', 'txt'), |
||
123 | new \Oara\Curl\Parameter('eventType', 'earnings'), // use 'all' to download all events |
||
124 | new \Oara\Curl\Parameter('startPostDate', $dStartDate->format('Y-m-d')), |
||
125 | new \Oara\Curl\Parameter('endPostDate', $dEndDate->format('Y-m-d')), |
||
126 | ); |
||
127 | $url = new \Oara\Curl\Request("https://api.epn.ebay.com/rpt/events/v1/detail/tdr", $postParams ); |
||
128 | |||
129 | |||
130 | $urls[] = $url; |
||
131 | $exportData = array(); |
||
132 | |||
133 | try { |
||
134 | $exportReport = $this->_client->post($urls, 0); |
||
135 | $exportData = \str_getcsv($exportReport[0], "\n"); |
||
136 | } catch (\Exception $e) { |
||
137 | // ignore any error |
||
138 | } |
||
139 | |||
140 | // OLD Version - URL Doesn't work anymore - 2017-08-31 <PN> |
||
141 | /* |
||
142 | $urls = array(); |
||
143 | $urls[] = new \Oara\Curl\Request("https://publisher.ebaypartnernetwork.com/PublisherReportsTx?pt=2&start_date={$dStartDate->format("n/j/Y")}&end_date={$dEndDate->format("n/j/Y")}&user_name={$this->_credentials['user']}&user_password={$this->_credentials['password']}&advIdProgIdCombo=&tx_fmt=3&submit_tx=Download", array()); |
||
144 | $exportData = array(); |
||
145 | try { |
||
146 | $exportReport = $this->_client->get($urls, 'content', 5); |
||
147 | $exportData = \str_getcsv($exportReport[0], "\n"); |
||
148 | } catch (\Exception $e) { |
||
149 | |||
150 | */ |
||
151 | $num = \count($exportData); |
||
152 | for ($i = 1; $i < $num; $i++) { |
||
153 | $transactionExportArray = \str_getcsv($exportData[$i], "\t"); |
||
154 | |||
155 | if ($transactionExportArray[2] == "Winning Bid (Revenue)" && (empty($this->_sitesAllowed) || \in_array($transactionExportArray[5], $this->_sitesAllowed))) { |
||
156 | $transaction = Array(); |
||
157 | $transaction['merchantId'] = 0; |
||
158 | $transaction['merchantName'] = ''; |
||
159 | $transaction['unique_id'] = $transactionExportArray[18]; |
||
160 | $transactionDate = \DateTime::createFromFormat("Y-m-d", $transactionExportArray[0]); |
||
161 | $transaction['date'] = $transactionDate->format("Y-m-d") . ' 00:00:00'; |
||
162 | $postDate = \DateTime::createFromFormat("Y-m-d", $transactionExportArray[1]); |
||
163 | $transaction['post_date'] = $postDate->format("Y-m-d") . ' 00:00:00'; |
||
164 | if ($transactionExportArray[10] != null) { |
||
165 | $transaction['custom_id'] = $transactionExportArray[10]; |
||
166 | } |
||
167 | $transaction['click_date'] = $transactionExportArray[11]; |
||
168 | $transaction['ebay_amount'] = (float) $transactionExportArray[3]; |
||
169 | $transaction['amount'] = (float) $transactionExportArray[15]; |
||
170 | $transaction['commission'] = (float) $transactionExportArray[20]; |
||
171 | // Set status as Pending |
||
172 | // ... real status (approved / denied) must be calculated by summing all negative/positive records |
||
173 | // ... and checking final amount for a positive or zero value |
||
174 | $transaction['status'] = \Oara\Utilities::STATUS_PENDING; |
||
175 | $totalTransactions[] = $transaction; |
||
176 | } |
||
177 | } |
||
178 | return $totalTransactions; |
||
179 | } |
||
180 | } |
||
181 |
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: