| Conditions | 12 |
| Paths | 34 |
| Total Lines | 40 |
| Lines | 40 |
| Ratio | 100 % |
| 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 |
||
| 104 | View Code Duplication | public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()): array |
|
| 105 | { |
||
| 106 | |||
| 107 | $arrResult = array(); |
||
| 108 | $transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo); |
||
| 109 | |||
| 110 | foreach ($transactionList as $transaction) { |
||
| 111 | if (isset($transaction['commission']) && $transaction['commission'] < 0){ |
||
| 112 | continue; |
||
| 113 | } |
||
| 114 | $Transaction = Transaction::createInstance(); |
||
| 115 | if (isset($transaction['currency']) && !empty($transaction['currency'])) { |
||
| 116 | $Transaction->currency = $transaction['currency']; |
||
| 117 | } else { |
||
| 118 | $Transaction->currency = "EUR"; |
||
| 119 | } |
||
| 120 | $Transaction->status = $transaction['status']; |
||
| 121 | $Transaction->amount = $transaction['amount']; |
||
| 122 | array_key_exists_safe($transaction, 'custom_id') ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = ''; |
||
| 123 | $Transaction->unique_ID = $transaction['unique_id']; |
||
| 124 | $Transaction->commission = $transaction['commission']; |
||
| 125 | $Transaction->date = new \DateTime($transaction['date']); |
||
| 126 | // Future use - Only few providers returns these dates values - <PN> - 2017-06-29 |
||
| 127 | if (isset($transaction['click_date']) && !empty($transaction['click_date'])) { |
||
| 128 | $Transaction->click_date = new \DateTime($transaction['click_date']); |
||
| 129 | } |
||
| 130 | if (isset($transaction['update_date']) && !empty($transaction['update_date'])) { |
||
| 131 | $Transaction->update_date = new \DateTime($transaction['update_date']); |
||
| 132 | } |
||
| 133 | $Transaction->merchant_ID = $transaction['merchantId']; |
||
| 134 | $Transaction->campaign_name = $transaction['merchantName']; |
||
| 135 | $Transaction->approved = false; |
||
| 136 | if ($Transaction->status == \Oara\Utilities::STATUS_CONFIRMED) { |
||
| 137 | $Transaction->approved = true; |
||
| 138 | } |
||
| 139 | $arrResult[] = $Transaction; |
||
| 140 | } |
||
| 141 | |||
| 142 | return $arrResult; |
||
| 143 | } |
||
| 144 | |||
| 172 |
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: