Code cleanup.

This commit is contained in:
James Cole
2023-12-20 19:35:52 +01:00
parent c4f6366642
commit 64ec0cf62e
997 changed files with 12908 additions and 28136 deletions

View File

@@ -34,12 +34,6 @@ trait CalculateRangeOccurrences
/**
* Get the number of daily occurrences for a recurring transaction until date $end is reached. Will skip every
* $skipMod-1 occurrences.
*
* @param Carbon $start
* @param Carbon $end
* @param int $skipMod
*
* @return array
*/
protected function getDailyInRange(Carbon $start, Carbon $end, int $skipMod): array
{
@@ -50,7 +44,7 @@ trait CalculateRangeOccurrences
$return[] = clone $start;
}
$start->addDay();
$attempts++;
++$attempts;
}
return $return;
@@ -59,14 +53,6 @@ trait CalculateRangeOccurrences
/**
* Get the number of daily occurrences for a recurring transaction until date $end is reached. Will skip every
* $skipMod-1 occurrences.
*
* @param Carbon $start
* @param Carbon $end
* @param int $skipMod
* @param string $moment
*
* @return array
*
*/
protected function getMonthlyInRange(Carbon $start, Carbon $end, int $skipMod, string $moment): array
{
@@ -83,7 +69,7 @@ trait CalculateRangeOccurrences
if (0 === $attempts % $skipMod && $start->lte($start) && $end->gte($start)) {
$return[] = clone $start;
}
$attempts++;
++$attempts;
$start->endOfMonth()->startOfDay()->addDay();
}
@@ -93,13 +79,6 @@ trait CalculateRangeOccurrences
/**
* Get the number of daily occurrences for a recurring transaction until date $end is reached. Will skip every
* $skipMod-1 occurrences.
*
* @param Carbon $start
* @param Carbon $end
* @param int $skipMod
* @param string $moment
*
* @return array
*/
protected function getNdomInRange(Carbon $start, Carbon $end, int $skipMod, string $moment): array
{
@@ -107,8 +86,8 @@ trait CalculateRangeOccurrences
$attempts = 0;
$start->startOfMonth();
// this feels a bit like a cop out but why reinvent the wheel?
$counters = [1 => 'first', 2 => 'second', 3 => 'third', 4 => 'fourth', 5 => 'fifth',];
$daysOfWeek = [1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 7 => 'Sunday',];
$counters = [1 => 'first', 2 => 'second', 3 => 'third', 4 => 'fourth', 5 => 'fifth'];
$daysOfWeek = [1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 7 => 'Sunday'];
$parts = explode(',', $moment);
while ($start <= $end) {
$string = sprintf('%s %s of %s %s', $counters[$parts[0]], $daysOfWeek[$parts[1]], $start->format('F'), $start->format('Y'));
@@ -116,7 +95,7 @@ trait CalculateRangeOccurrences
if (0 === $attempts % $skipMod) {
$return[] = clone $newCarbon;
}
$attempts++;
++$attempts;
$start->endOfMonth()->addDay();
}
@@ -126,14 +105,6 @@ trait CalculateRangeOccurrences
/**
* Get the number of daily occurrences for a recurring transaction until date $end is reached. Will skip every
* $skipMod-1 occurrences.
*
* @param Carbon $start
* @param Carbon $end
* @param int $skipMod
* @param string $moment
*
* @return array
*
*/
protected function getWeeklyInRange(Carbon $start, Carbon $end, int $skipMod, string $moment): array
{
@@ -160,7 +131,7 @@ trait CalculateRangeOccurrences
app('log')->debug('Date is in range of start+end, add to set.');
$return[] = clone $start;
}
$attempts++;
++$attempts;
$start->addWeek();
app('log')->debug(sprintf('Mutator is now (end of loop): %s', $start->format('Y-m-d')));
}
@@ -171,14 +142,6 @@ trait CalculateRangeOccurrences
/**
* Get the number of daily occurrences for a recurring transaction until date $end is reached. Will skip every
* $skipMod-1 occurrences.
*
* @param Carbon $start
* @param Carbon $end
* @param int $skipMod
* @param string $moment
*
* @return array
*
*/
protected function getYearlyInRange(Carbon $start, Carbon $end, int $skipMod, string $moment): array
{
@@ -198,8 +161,8 @@ trait CalculateRangeOccurrences
$return[] = clone $obj;
}
$obj->addYears();
$count++;
$attempts++;
++$count;
++$attempts;
}
return $return;