Conditions | 6 |
Paths | 32 |
Total Lines | 60 |
Code Lines | 43 |
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 |
||
195 | public static function fromTransaction(Transaction $transaction): Entry |
||
196 | { |
||
197 | $entry = new self(); |
||
198 | $entry->journal_id = $transaction->journal_id; |
||
199 | $entry->transaction_id = $transaction->id; |
||
200 | $entry->date = $transaction->date->format('Ymd'); |
||
201 | $entry->description = $transaction->description; |
||
202 | if (strlen((string)$transaction->transaction_description) > 0) { |
||
203 | $entry->description = $transaction->transaction_description . '(' . $transaction->description . ')'; |
||
204 | } |
||
205 | $entry->currency_code = $transaction->transactionCurrency->code; |
||
206 | $entry->amount = (string)round($transaction->transaction_amount, $transaction->transactionCurrency->decimal_places); |
||
|
|||
207 | |||
208 | $entry->foreign_currency_code = null === $transaction->foreign_currency_id ? null : $transaction->foreignCurrency->code; |
||
209 | $entry->foreign_amount = null === $transaction->foreign_currency_id |
||
210 | ? null |
||
211 | : (string)round( |
||
212 | $transaction->transaction_foreign_amount, |
||
213 | $transaction->foreignCurrency->decimal_places |
||
214 | ); |
||
215 | |||
216 | $entry->transaction_type = $transaction->transaction_type_type; |
||
217 | $entry->asset_account_id = (string)$transaction->account_id; |
||
218 | $entry->asset_account_name = app('steam')->tryDecrypt($transaction->account_name); |
||
219 | $entry->asset_account_iban = $transaction->account_iban; |
||
220 | $entry->asset_account_number = $transaction->account_number; |
||
221 | $entry->asset_account_bic = $transaction->account_bic; |
||
222 | $entry->asset_currency_code = $transaction->account_currency_code; |
||
223 | |||
224 | $entry->opposing_account_id = (string)$transaction->opposing_account_id; |
||
225 | $entry->opposing_account_name = app('steam')->tryDecrypt($transaction->opposing_account_name); |
||
226 | $entry->opposing_account_iban = $transaction->opposing_account_iban; |
||
227 | $entry->opposing_account_number = $transaction->opposing_account_number; |
||
228 | $entry->opposing_account_bic = $transaction->opposing_account_bic; |
||
229 | $entry->opposing_currency_code = $transaction->opposing_currency_code; |
||
230 | |||
231 | // budget |
||
232 | $entry->budget_id = (string)$transaction->transaction_budget_id; |
||
233 | $entry->budget_name = app('steam')->tryDecrypt($transaction->transaction_budget_name); |
||
234 | if (null === $transaction->transaction_budget_id) { |
||
235 | $entry->budget_id = $transaction->transaction_journal_budget_id; |
||
236 | $entry->budget_name = app('steam')->tryDecrypt($transaction->transaction_journal_budget_name); |
||
237 | } |
||
238 | |||
239 | // category |
||
240 | $entry->category_id = (string)$transaction->transaction_category_id; |
||
241 | $entry->category_name = app('steam')->tryDecrypt($transaction->transaction_category_name); |
||
242 | if (null === $transaction->transaction_category_id) { |
||
243 | $entry->category_id = $transaction->transaction_journal_category_id; |
||
244 | $entry->category_name = app('steam')->tryDecrypt($transaction->transaction_journal_category_name); |
||
245 | } |
||
246 | |||
247 | // budget |
||
248 | $entry->bill_id = (string)$transaction->bill_id; |
||
249 | $entry->bill_name = app('steam')->tryDecrypt($transaction->bill_name); |
||
250 | |||
251 | $entry->tags = $transaction->tags; |
||
252 | $entry->notes = $transaction->notes; |
||
253 | |||
254 | return $entry; |
||
255 | } |
||
257 |