chore: code cleanup.

This commit is contained in:
James Cole
2023-05-29 13:56:55 +02:00
parent 7f7644c92f
commit 1b52147a05
295 changed files with 12418 additions and 12324 deletions

View File

@@ -143,6 +143,53 @@ class BillTransformer extends AbstractTransformer
];
}
/**
* Returns the latest date in the set, or start when set is empty.
*
* @param Collection $dates
* @param Carbon $default
*
* @return Carbon
*/
protected function lastPaidDate(Collection $dates, Carbon $default): Carbon
{
if (0 === $dates->count()) {
return $default;
}
$latest = $dates->first()->date;
/** @var TransactionJournal $journal */
foreach ($dates as $journal) {
if ($journal->date->gte($latest)) {
$latest = $journal->date;
}
}
return $latest;
}
/**
* Given a bill and a date, this method will tell you at which moment this bill expects its next
* transaction. Whether or not it is there already, is not relevant.
*
* @param Bill $bill
* @param Carbon $date
*
* @return Carbon
*/
protected function nextDateMatch(Bill $bill, Carbon $date): Carbon
{
//Log::debug(sprintf('Now in nextDateMatch(%d, %s)', $bill->id, $date->format('Y-m-d')));
$start = clone $bill->date;
//Log::debug(sprintf('Bill start date is %s', $start->format('Y-m-d')));
while ($start < $date) {
$start = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
}
//Log::debug(sprintf('End of loop, bill start date is now %s', $start->format('Y-m-d')));
return $start;
}
/**
* Get the data the bill was paid and predict the next expected match.
*
@@ -217,30 +264,6 @@ class BillTransformer extends AbstractTransformer
];
}
/**
* Returns the latest date in the set, or start when set is empty.
*
* @param Collection $dates
* @param Carbon $default
*
* @return Carbon
*/
protected function lastPaidDate(Collection $dates, Carbon $default): Carbon
{
if (0 === $dates->count()) {
return $default;
}
$latest = $dates->first()->date;
/** @var TransactionJournal $journal */
foreach ($dates as $journal) {
if ($journal->date->gte($latest)) {
$latest = $journal->date;
}
}
return $latest;
}
/**
* @param Bill $bill
*
@@ -280,27 +303,4 @@ class BillTransformer extends AbstractTransformer
return $simple->toArray();
}
/**
* Given a bill and a date, this method will tell you at which moment this bill expects its next
* transaction. Whether or not it is there already, is not relevant.
*
* @param Bill $bill
* @param Carbon $date
*
* @return Carbon
*/
protected function nextDateMatch(Bill $bill, Carbon $date): Carbon
{
//Log::debug(sprintf('Now in nextDateMatch(%d, %s)', $bill->id, $date->format('Y-m-d')));
$start = clone $bill->date;
//Log::debug(sprintf('Bill start date is %s', $start->format('Y-m-d')));
while ($start < $date) {
$start = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
}
//Log::debug(sprintf('End of loop, bill start date is now %s', $start->format('Y-m-d')));
return $start;
}
}