| Conditions | 10 |
| Paths | 33 |
| Total Lines | 38 |
| Code Lines | 26 |
| 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 |
||
| 120 | public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
||
| 121 | { |
||
| 122 | $arrResult = array(); |
||
| 123 | $transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo); |
||
| 124 | foreach($transactionList as $transaction) { |
||
| 125 | $Transaction = Transaction::createInstance(); |
||
| 126 | |||
| 127 | if (isset($transaction['currency']) && !empty($transaction['currency'])) { |
||
| 128 | $Transaction->currency = $transaction['currency']; |
||
| 129 | } else { |
||
| 130 | $Transaction->currency = "EUR"; |
||
| 131 | } |
||
| 132 | $Transaction->status = $transaction['status']; |
||
| 133 | $Transaction->amount = $transaction['amount']; |
||
| 134 | array_key_exists_safe( $transaction,'custom_id' ) ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = ''; |
||
| 135 | $Transaction->title = ''; |
||
| 136 | $Transaction->unique_ID = $transaction['unique_id']; |
||
| 137 | $Transaction->commission = $transaction['commission']; |
||
| 138 | $date = new \DateTime($transaction['date']); |
||
| 139 | $Transaction->date = $date; // $date->format('Y-m-d H:i:s'); |
||
| 140 | // Future use - Only few providers returns these dates values - <PN> - 2017-06-29 |
||
| 141 | if (isset($transaction['click_date']) && !empty($transaction['click_date'])) { |
||
| 142 | $Transaction->click_date = new \DateTime($transaction['click_date']); |
||
| 143 | } |
||
| 144 | if (isset($transaction['post_date']) && !empty($transaction['post_date'])) { |
||
| 145 | $Transaction->update_date = new \DateTime($transaction['post_date']); |
||
| 146 | } |
||
| 147 | // $Transaction->merchant_ID = $transaction['merchantId']; |
||
| 148 | // $Transaction->campaign_name = $transaction['merchantName']; |
||
| 149 | // $Transaction->IP = $transaction['IP']; |
||
| 150 | $Transaction->approved = false; |
||
| 151 | if ($Transaction->status==\Oara\Utilities::STATUS_CONFIRMED){ |
||
| 152 | $Transaction->approved = true; |
||
| 153 | } |
||
| 154 | $arrResult[] = $Transaction; |
||
| 155 | } |
||
| 156 | return $arrResult; |
||
| 157 | } |
||
| 158 | |||
| 187 |
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: