Skip to content

Commit

Permalink
factorize code
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas CHERIFI committed Apr 10, 2016
1 parent eb5db0f commit 0b23618
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
18 changes: 5 additions & 13 deletions Processor/LclProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,14 @@ public function format(ArrayCollection $data)
$date = new \DateTime();
$date->setDate(2000 + (int) substr($dateRaw, 6, 2), (int) substr($dateRaw, 3, 2), (int) substr($dateRaw, 0, 2));
$date->setTime(12, 0, 0);
// Value
$debitRaw = $item[3];
if (strlen($debitRaw)) {
$value = abs((float) str_replace(',', '.', str_replace(' ', '', $debitRaw)));
$debit = true;
} else {
$creditRaw = $item[4];
$value = (float) str_replace(',', '.', str_replace(' ', '', $creditRaw));
$debit = false;
}
// Transaction
$transaction = $this->frenchTransactionFormatter($item[3], $item[4]);

return [
'date' => $date,
'date' => $date,
'label' => $item[1],
'value' => $value,
'debit' => $debit,
'value' => $transaction['value'],
'debit' => $transaction['debit'],
];
});

Expand Down
19 changes: 18 additions & 1 deletion Processor/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,24 @@ public function __toString()
return (string) $this->configuration['name'];
}

public function frenchDateFormatter($raw)
/**
* @param string $debitRaw
* @param string $creditRaw
*
* @return array
*/
public function frenchTransactionFormatter($debitRaw, $creditRaw)
{
if (strlen($debitRaw)) {
$value = abs((float) str_replace(',', '.', str_replace(' ', '', $debitRaw)));
$debit = true;
} else {
$value = (float) str_replace(',', '.', str_replace(' ', '', $creditRaw));
$debit = false;
}
return [
'value' => $value,
'debit' => $debit,
];
}
}
16 changes: 4 additions & 12 deletions Processor/SgProProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,15 @@ public function format(ArrayCollection $data)
$valueDate->setDate((int) substr($dateRaw, 6, 4), (int) substr($dateRaw, 3, 2), (int) substr($dateRaw, 0, 2));
$valueDate->setTime(12, 0, 0);

// Value
$debitRaw = $item[3];
if (strlen($debitRaw)) {
$value = abs((float) str_replace(',', '.', str_replace('.', '', $debitRaw)));
$debit = true;
} else {
$creditRaw = $item[4];
$value = (float) str_replace(',', '.', str_replace('.', '', $creditRaw));
$debit = false;
}
// Transaction
$transaction = $this->frenchTransactionFormatter($item[3], $item[4]);

return [
'date' => $date,
'value_date' => $valueDate,
'label' => $item[2],
'value' => $value,
'debit' => $debit,
'value' => $transaction['value'],
'debit' => $transaction['debit'],
];
});

Expand Down

0 comments on commit 0b23618

Please sign in to comment.