Conditions | 2 |
Paths | 2 |
Total Lines | 92 |
Code Lines | 55 |
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 |
||
197 | private function getTransactionData(): array |
||
198 | { |
||
199 | $return = []; |
||
200 | /** |
||
201 | * @var int $index |
||
202 | * @var array $transaction |
||
203 | */ |
||
204 | foreach ($this->get('transactions') as $index => $transaction) { |
||
205 | $object = new NullArrayObject($transaction); |
||
206 | $return[] = [ |
||
207 | 'type' => $this->stringFromValue($object['type']), |
||
208 | 'date' => $this->dateFromValue($object['date']), |
||
209 | 'order' => $this->integerFromValue((string)$object['order']), |
||
210 | |||
211 | 'currency_id' => $this->integerFromValue((string)$object['currency_id']), |
||
212 | 'currency_code' => $this->stringFromValue($object['currency_code']), |
||
213 | |||
214 | // foreign currency info: |
||
215 | 'foreign_currency_id' => $this->integerFromValue((string)$object['foreign_currency_id']), |
||
216 | 'foreign_currency_code' => $this->stringFromValue($object['foreign_currency_code']), |
||
217 | |||
218 | // amount and foreign amount. Cannot be 0. |
||
219 | 'amount' => $this->stringFromValue((string)$object['amount']), |
||
220 | 'foreign_amount' => $this->stringFromValue((string)$object['foreign_amount']), |
||
221 | |||
222 | // description. |
||
223 | 'description' => $this->stringFromValue($object['description']), |
||
224 | |||
225 | // source of transaction. If everything is null, assume cash account. |
||
226 | 'source_id' => $this->integerFromValue((string)$object['source_id']), |
||
227 | 'source_name' => $this->stringFromValue($object['source_name']), |
||
228 | 'source_iban' => $this->stringFromValue($object['source_iban']), |
||
229 | 'source_number' => $this->stringFromValue($object['source_number']), |
||
230 | 'source_bic' => $this->stringFromValue($object['source_bic']), |
||
231 | |||
232 | // destination of transaction. If everything is null, assume cash account. |
||
233 | 'destination_id' => $this->integerFromValue((string)$object['destination_id']), |
||
234 | 'destination_name' => $this->stringFromValue($object['destination_name']), |
||
235 | 'destination_iban' => $this->stringFromValue($object['destination_iban']), |
||
236 | 'destination_number' => $this->stringFromValue($object['destination_number']), |
||
237 | 'destination_bic' => $this->stringFromValue($object['destination_bic']), |
||
238 | |||
239 | // budget info |
||
240 | 'budget_id' => $this->integerFromValue((string)$object['budget_id']), |
||
241 | 'budget_name' => $this->stringFromValue($object['budget_name']), |
||
242 | |||
243 | // category info |
||
244 | 'category_id' => $this->integerFromValue((string)$object['category_id']), |
||
245 | 'category_name' => $this->stringFromValue($object['category_name']), |
||
246 | |||
247 | // journal bill reference. Optional. Will only work for withdrawals |
||
248 | 'bill_id' => $this->integerFromValue((string)$object['bill_id']), |
||
249 | 'bill_name' => $this->stringFromValue($object['bill_name']), |
||
250 | |||
251 | // piggy bank reference. Optional. Will only work for transfers |
||
252 | 'piggy_bank_id' => $this->integerFromValue((string)$object['piggy_bank_id']), |
||
253 | 'piggy_bank_name' => $this->stringFromValue($object['piggy_bank_name']), |
||
254 | |||
255 | // some other interesting properties |
||
256 | 'reconciled' => $this->convertBoolean((string)$object['reconciled']), |
||
257 | 'notes' => $this->nlStringFromValue($object['notes']), |
||
258 | 'tags' => $this->arrayFromValue($object['tags']), |
||
259 | |||
260 | // all custom fields: |
||
261 | 'internal_reference' => $this->stringFromValue($object['internal_reference']), |
||
262 | 'external_id' => $this->stringFromValue($object['external_id']), |
||
263 | 'original_source' => sprintf('ff3-v%s|api-v%s', config('firefly.version'), config('firefly.api_version')), |
||
264 | 'recurrence_id' => $this->integerFromValue($object['recurrence_id']), |
||
265 | 'bunq_payment_id' => $this->stringFromValue($object['bunq_payment_id']), |
||
266 | |||
267 | 'sepa_cc' => $this->stringFromValue($object['sepa_cc']), |
||
268 | 'sepa_ct_op' => $this->stringFromValue($object['sepa_ct_op']), |
||
269 | 'sepa_ct_id' => $this->stringFromValue($object['sepa_ct_id']), |
||
270 | 'sepa_db' => $this->stringFromValue($object['sepa_db']), |
||
271 | 'sepa_country' => $this->stringFromValue($object['sepa_country']), |
||
272 | 'sepa_ep' => $this->stringFromValue($object['sepa_ep']), |
||
273 | 'sepa_ci' => $this->stringFromValue($object['sepa_ci']), |
||
274 | 'sepa_batch_id' => $this->stringFromValue($object['sepa_batch_id']), |
||
275 | |||
276 | |||
277 | // custom date fields. Must be Carbon objects. Presence is optional. |
||
278 | 'interest_date' => $this->dateFromValue($object['interest_date']), |
||
279 | 'book_date' => $this->dateFromValue($object['book_date']), |
||
280 | 'process_date' => $this->dateFromValue($object['process_date']), |
||
281 | 'due_date' => $this->dateFromValue($object['due_date']), |
||
282 | 'payment_date' => $this->dateFromValue($object['payment_date']), |
||
283 | 'invoice_date' => $this->dateFromValue($object['invoice_date']), |
||
284 | |||
285 | ]; |
||
286 | } |
||
287 | |||
288 | return $return; |
||
289 | } |
||
291 |