Conditions | 13 |
Paths | 345 |
Total Lines | 51 |
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 |
||
101 | public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()): array |
||
102 | { |
||
103 | $arrResult = array(); |
||
104 | try { |
||
105 | $transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo); |
||
106 | foreach ($transactionList as $transaction) { |
||
107 | $Transaction = Transaction::createInstance(); |
||
108 | if (isset($transaction['currency']) && !empty($transaction['currency'])) { |
||
109 | $Transaction->currency = $transaction['currency']; |
||
110 | } else { |
||
111 | $Transaction->currency = "EUR"; |
||
112 | } |
||
113 | $Transaction->status = $transaction['status']; |
||
114 | $Transaction->action = $transaction['action']; |
||
115 | $Transaction->amount = $transaction['amount']; |
||
116 | array_key_exists_safe($transaction, 'custom_id') ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = ''; |
||
117 | $Transaction->title = $transaction['title']; |
||
118 | $Transaction->referrer = $transaction['referrer']; |
||
119 | $Transaction->unique_ID = $transaction['unique_id']; |
||
120 | $Transaction->commission = $transaction['commission']; |
||
121 | $date = new \DateTime($transaction['date']); |
||
122 | $Transaction->date = $date; |
||
123 | // Future use - Only few providers returns these dates values - <PN> - 2017-06-29 |
||
124 | if (isset($transaction['click_date']) && !empty($transaction['click_date'])) { |
||
125 | $Transaction->click_date = new \DateTime($transaction['click_date']); |
||
126 | } |
||
127 | if (isset($transaction['update_date']) && !empty($transaction['update_date'])) { |
||
128 | $Transaction->update_date = new \DateTime($transaction['update_date']); |
||
129 | } |
||
130 | if (isset($transaction['paid_date']) && !empty($transaction['paid_date'])) { |
||
131 | $Transaction->paid_date = new \DateTime($transaction['paid_date']); |
||
132 | $Transaction->paid = true; |
||
133 | } |
||
134 | $Transaction->merchant_ID = $transaction['merchantId']; |
||
135 | $Transaction->campaign_name = $transaction['merchantName']; |
||
136 | $Transaction->approved = false; |
||
137 | if ($Transaction->status == \Oara\Utilities::STATUS_CONFIRMED) { |
||
138 | $Transaction->approved = true; |
||
139 | } |
||
140 | $arrResult[] = $Transaction; |
||
141 | } |
||
142 | |||
143 | } catch (\Exception $e) { |
||
144 | echo "[EasyMarketing][getSales][Exception] " . $e->getMessage() . PHP_EOL; |
||
145 | var_dump($e->getTraceAsString()); |
||
146 | throw new \Exception($e); |
||
147 | } |
||
148 | |||
149 | return $arrResult; |
||
150 | |||
151 | } |
||
152 | |||
184 |
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: