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;

View File

@@ -34,12 +34,6 @@ trait CalculateXOccurrences
/**
* Calculates the number of daily occurrences for a recurring transaction, starting at the date, until $count is
* reached. It will skip over $skipMod -1 recurrences.
*
* @param Carbon $date
* @param int $count
* @param int $skipMod
*
* @return array
*/
protected function getXDailyOccurrences(Carbon $date, int $count, int $skipMod): array
{
@@ -51,9 +45,9 @@ trait CalculateXOccurrences
$mutator->addDay();
if (0 === $attempts % $skipMod) {
$return[] = clone $mutator;
$total++;
++$total;
}
$attempts++;
++$attempts;
}
return $return;
@@ -62,13 +56,6 @@ trait CalculateXOccurrences
/**
* Calculates the number of monthly occurrences for a recurring transaction, starting at the date, until $count is
* reached. It will skip over $skipMod -1 recurrences.
*
* @param Carbon $date
* @param int $count
* @param int $skipMod
* @param string $moment
*
* @return array
*/
protected function getXMonthlyOccurrences(Carbon $date, int $count, int $skipMod, string $moment): array
{
@@ -87,9 +74,9 @@ trait CalculateXOccurrences
$mutator->day = $domCorrected;
if (0 === $attempts % $skipMod) {
$return[] = clone $mutator;
$total++;
++$total;
}
$attempts++;
++$attempts;
$mutator->endOfMonth()->addDay();
}
@@ -99,13 +86,6 @@ trait CalculateXOccurrences
/**
* Calculates the number of NDOM occurrences for a recurring transaction, starting at the date, until $count is
* reached. It will skip over $skipMod -1 recurrences.
*
* @param Carbon $date
* @param int $count
* @param int $skipMod
* @param string $moment
*
* @return array
*/
protected function getXNDomOccurrences(Carbon $date, int $count, int $skipMod, string $moment): array
{
@@ -116,8 +96,8 @@ trait CalculateXOccurrences
$mutator->addDay(); // always assume today has passed.
$mutator->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 ($total < $count) {
@@ -125,9 +105,9 @@ trait CalculateXOccurrences
$newCarbon = new Carbon($string);
if (0 === $attempts % $skipMod) {
$return[] = clone $newCarbon;
$total++;
++$total;
}
$attempts++;
++$attempts;
$mutator->endOfMonth()->addDay();
}
@@ -137,13 +117,6 @@ trait CalculateXOccurrences
/**
* Calculates the number of weekly occurrences for a recurring transaction, starting at the date, until $count is
* reached. It will skip over $skipMod -1 recurrences.
*
* @param Carbon $date
* @param int $count
* @param int $skipMod
* @param string $moment
*
* @return array
*/
protected function getXWeeklyOccurrences(Carbon $date, int $count, int $skipMod, string $moment): array
{
@@ -167,9 +140,9 @@ trait CalculateXOccurrences
while ($total < $count) {
if (0 === $attempts % $skipMod) {
$return[] = clone $mutator;
$total++;
++$total;
}
$attempts++;
++$attempts;
$mutator->addWeek();
}
@@ -179,13 +152,6 @@ trait CalculateXOccurrences
/**
* Calculates the number of yearly occurrences for a recurring transaction, starting at the date, until $count is
* reached. It will skip over $skipMod -1 recurrences.
*
* @param Carbon $date
* @param int $count
* @param int $skipMod
* @param string $moment
*
* @return array
*/
protected function getXYearlyOccurrences(Carbon $date, int $count, int $skipMod, string $moment): array
{
@@ -202,10 +168,10 @@ trait CalculateXOccurrences
while ($total < $count) {
if (0 === $attempts % $skipMod) {
$return[] = clone $obj;
$total++;
++$total;
}
$obj->addYears();
$attempts++;
++$attempts;
}
return $return;

View File

@@ -34,13 +34,6 @@ trait CalculateXOccurrencesSince
/**
* Calculates the number of daily occurrences for a recurring transaction, starting at the date, until $count is
* reached. It will skip over $skipMod -1 recurrences.
*
* @param Carbon $date
* @param Carbon $afterDate
* @param int $count
* @param int $skipMod
*
* @return array
*/
protected function getXDailyOccurrencesSince(Carbon $date, Carbon $afterDate, int $count, int $skipMod): array
{
@@ -52,10 +45,10 @@ trait CalculateXOccurrencesSince
while ($total < $count) {
if (0 === $attempts % $skipMod && $mutator->gt($afterDate)) {
$return[] = clone $mutator;
$total++;
++$total;
}
$mutator->addDay();
$attempts++;
++$attempts;
}
return $return;
@@ -65,13 +58,6 @@ trait CalculateXOccurrencesSince
* Calculates the number of monthly occurrences for a recurring transaction, starting at the date, until $count is
* reached. It will skip over $skipMod -1 recurrences.
*
* @param Carbon $date
* @param Carbon $afterDate
* @param int $count
* @param int $skipMod
* @param string $moment
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
protected function getXMonthlyOccurrencesSince(Carbon $date, Carbon $afterDate, int $count, int $skipMod, string $moment): array
@@ -95,9 +81,9 @@ trait CalculateXOccurrencesSince
$mutator->day = $domCorrected;
if (0 === $attempts % $skipMod && $mutator->gte($afterDate)) {
$return[] = clone $mutator;
$total++;
++$total;
}
$attempts++;
++$attempts;
$mutator = $mutator->endOfMonth()->addDay();
app('log')->debug(sprintf('Mutator is now %s', $mutator->format('Y-m-d')));
}
@@ -109,13 +95,6 @@ trait CalculateXOccurrencesSince
* Calculates the number of NDOM occurrences for a recurring transaction, starting at the date, until $count is
* reached. It will skip over $skipMod -1 recurrences.
*
* @param Carbon $date
* @param Carbon $afterDate
* @param int $count
* @param int $skipMod
* @param string $moment
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
protected function getXNDomOccurrencesSince(Carbon $date, Carbon $afterDate, int $count, int $skipMod, string $moment): array
@@ -128,8 +107,8 @@ trait CalculateXOccurrencesSince
$mutator->addDay(); // always assume today has passed.
$mutator->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 ($total < $count) {
@@ -137,9 +116,9 @@ trait CalculateXOccurrencesSince
$newCarbon = new Carbon($string);
if (0 === $attempts % $skipMod && $mutator->gte($afterDate)) {
$return[] = clone $newCarbon;
$total++;
++$total;
}
$attempts++;
++$attempts;
$mutator->endOfMonth()->addDay();
}
@@ -150,13 +129,6 @@ trait CalculateXOccurrencesSince
* Calculates the number of weekly occurrences for a recurring transaction, starting at the date, until $count is
* reached. It will skip over $skipMod -1 recurrences.
*
* @param Carbon $date
* @param Carbon $afterDate
* @param int $count
* @param int $skipMod
* @param string $moment
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
protected function getXWeeklyOccurrencesSince(Carbon $date, Carbon $afterDate, int $count, int $skipMod, string $moment): array
@@ -169,7 +141,7 @@ trait CalculateXOccurrencesSince
// monday = 1
// sunday = 7
// Removed assumption today has passed, see issue https://github.com/firefly-iii/firefly-iii/issues/4798
//$mutator->addDay(); // always assume today has passed.
// $mutator->addDay(); // always assume today has passed.
$dayOfWeek = (int)$moment;
if ($mutator->dayOfWeekIso > $dayOfWeek) {
// day has already passed this week, add one week:
@@ -183,9 +155,9 @@ trait CalculateXOccurrencesSince
while ($total < $count) {
if (0 === $attempts % $skipMod && $mutator->gte($afterDate)) {
$return[] = clone $mutator;
$total++;
++$total;
}
$attempts++;
++$attempts;
$mutator->addWeek();
}
@@ -196,13 +168,6 @@ trait CalculateXOccurrencesSince
* Calculates the number of yearly occurrences for a recurring transaction, starting at the date, until $count is
* reached. It will skip over $skipMod -1 recurrences.
*
* @param Carbon $date
* @param Carbon $afterDate
* @param int $count
* @param int $skipMod
* @param string $moment
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
protected function getXYearlyOccurrencesSince(Carbon $date, Carbon $afterDate, int $count, int $skipMod, string $moment): array
@@ -229,10 +194,10 @@ trait CalculateXOccurrencesSince
if (0 === $attempts % $skipMod && $obj->gte($afterDate)) {
app('log')->debug('All conditions true, add obj.');
$return[] = clone $obj;
$total++;
++$total;
}
$obj->addYears();
$attempts++;
++$attempts;
}
return $return;

View File

@@ -35,53 +35,51 @@ trait FiltersWeekends
{
/**
* Filters out all weekend entries, if necessary.
*
* @param RecurrenceRepetition $repetition
* @param array $dates
*
* @return array
*
*/
protected function filterWeekends(RecurrenceRepetition $repetition, array $dates): array
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
if ($repetition->weekend === RecurrenceRepetition::WEEKEND_DO_NOTHING) {
if (RecurrenceRepetition::WEEKEND_DO_NOTHING === $repetition->weekend) {
app('log')->debug('Repetition will not be filtered on weekend days.');
return $dates;
}
$return = [];
/** @var Carbon $date */
foreach ($dates as $date) {
$isWeekend = $date->isWeekend();
if (!$isWeekend) {
$return[] = clone $date;
//app('log')->debug(sprintf('Date is %s, not a weekend date.', $date->format('D d M Y')));
// app('log')->debug(sprintf('Date is %s, not a weekend date.', $date->format('D d M Y')));
continue;
}
// is weekend and must set back to Friday?
if ($repetition->weekend === RecurrenceRepetition::WEEKEND_TO_FRIDAY) {
if (RecurrenceRepetition::WEEKEND_TO_FRIDAY === $repetition->weekend) {
$clone = clone $date;
$clone->addDays(5 - $date->dayOfWeekIso);
app('log')->debug(
sprintf('Date is %s, and this is in the weekend, so corrected to %s (Friday).', $date->format('D d M Y'), $clone->format('D d M Y'))
);
$return[] = clone $clone;
continue;
}
// postpone to Monday?
if ($repetition->weekend === RecurrenceRepetition::WEEKEND_TO_MONDAY) {
if (RecurrenceRepetition::WEEKEND_TO_MONDAY === $repetition->weekend) {
$clone = clone $date;
$clone->addDays(8 - $date->dayOfWeekIso);
app('log')->debug(
sprintf('Date is %s, and this is in the weekend, so corrected to %s (Monday).', $date->format('D d M Y'), $clone->format('D d M Y'))
);
$return[] = $clone;
continue;
}
//app('log')->debug(sprintf('Date is %s, removed from final result', $date->format('D d M Y')));
// app('log')->debug(sprintf('Date is %s, removed from final result', $date->format('D d M Y')));
}
// filter unique dates