Remove static references

This commit is contained in:
James Cole
2023-10-29 06:33:43 +01:00
parent 075d459b7c
commit 4f2159b54d
205 changed files with 1287 additions and 1287 deletions

View File

@@ -140,30 +140,30 @@ trait CalculateRangeOccurrences
{
$return = [];
$attempts = 0;
Log::debug('Rep is weekly.');
app('log')->debug('Rep is weekly.');
// monday = 1
// sunday = 7
$dayOfWeek = (int)$moment;
Log::debug(sprintf('DoW in repetition is %d, in mutator is %d', $dayOfWeek, $start->dayOfWeekIso));
app('log')->debug(sprintf('DoW in repetition is %d, in mutator is %d', $dayOfWeek, $start->dayOfWeekIso));
if ($start->dayOfWeekIso > $dayOfWeek) {
// day has already passed this week, add one week:
$start->addWeek();
Log::debug(sprintf('Jump to next week, so mutator is now: %s', $start->format('Y-m-d')));
app('log')->debug(sprintf('Jump to next week, so mutator is now: %s', $start->format('Y-m-d')));
}
// today is wednesday (3), expected is friday (5): add two days.
// today is friday (5), expected is monday (1), subtract four days.
Log::debug(sprintf('Mutator is now: %s', $start->format('Y-m-d')));
app('log')->debug(sprintf('Mutator is now: %s', $start->format('Y-m-d')));
$dayDifference = $dayOfWeek - $start->dayOfWeekIso;
$start->addDays($dayDifference);
Log::debug(sprintf('Mutator is now: %s', $start->format('Y-m-d')));
app('log')->debug(sprintf('Mutator is now: %s', $start->format('Y-m-d')));
while ($start <= $end) {
if (0 === $attempts % $skipMod && $start->lte($start) && $end->gte($start)) {
Log::debug('Date is in range of start+end, add to set.');
app('log')->debug('Date is in range of start+end, add to set.');
$return[] = clone $start;
}
$attempts++;
$start->addWeek();
Log::debug(sprintf('Mutator is now (end of loop): %s', $start->format('Y-m-d')));
app('log')->debug(sprintf('Mutator is now (end of loop): %s', $start->format('Y-m-d')));
}
return $return;

View File

@@ -45,7 +45,7 @@ trait CalculateXOccurrencesSince
*/
protected function getXDailyOccurrencesSince(Carbon $date, Carbon $afterDate, int $count, int $skipMod): array
{
Log::debug(sprintf('Now in %s', __METHOD__));
app('log')->debug(sprintf('Now in %s', __METHOD__));
$return = [];
$mutator = clone $date;
$total = 0;
@@ -76,7 +76,7 @@ trait CalculateXOccurrencesSince
*/
protected function getXMonthlyOccurrencesSince(Carbon $date, Carbon $afterDate, int $count, int $skipMod, string $moment): array
{
Log::debug(sprintf('Now in %s(%s, %s, %d)', __METHOD__, $date->format('Y-m-d'), $afterDate->format('Y-m-d'), $count));
app('log')->debug(sprintf('Now in %s(%s, %s, %d)', __METHOD__, $date->format('Y-m-d'), $afterDate->format('Y-m-d'), $count));
$return = [];
$mutator = clone $date;
$total = 0;
@@ -84,10 +84,10 @@ trait CalculateXOccurrencesSince
$dayOfMonth = (int)$moment;
$dayOfMonth = 0 === $dayOfMonth ? 1 : $dayOfMonth;
if ($mutator->day > $dayOfMonth) {
Log::debug(sprintf('%d is after %d, add a month. Mutator is now', $mutator->day, $dayOfMonth));
app('log')->debug(sprintf('%d is after %d, add a month. Mutator is now', $mutator->day, $dayOfMonth));
// day has passed already, add a month.
$mutator->addMonth();
Log::debug(sprintf('%s', $mutator->format('Y-m-d')));
app('log')->debug(sprintf('%s', $mutator->format('Y-m-d')));
}
while ($total < $count) {
@@ -99,7 +99,7 @@ trait CalculateXOccurrencesSince
}
$attempts++;
$mutator = $mutator->endOfMonth()->addDay();
Log::debug(sprintf('Mutator is now %s', $mutator->format('Y-m-d')));
app('log')->debug(sprintf('Mutator is now %s', $mutator->format('Y-m-d')));
}
return $return;
@@ -119,7 +119,7 @@ trait CalculateXOccurrencesSince
*/
protected function getXNDomOccurrencesSince(Carbon $date, Carbon $afterDate, int $count, int $skipMod, string $moment): array
{
Log::debug(sprintf('Now in %s', __METHOD__));
app('log')->debug(sprintf('Now in %s', __METHOD__));
$return = [];
$total = 0;
$attempts = 0;
@@ -159,7 +159,7 @@ trait CalculateXOccurrencesSince
*/
protected function getXWeeklyOccurrencesSince(Carbon $date, Carbon $afterDate, int $count, int $skipMod, string $moment): array
{
Log::debug(sprintf('Now in %s', __METHOD__));
app('log')->debug(sprintf('Now in %s', __METHOD__));
$return = [];
$total = 0;
$attempts = 0;
@@ -204,7 +204,7 @@ trait CalculateXOccurrencesSince
*/
protected function getXYearlyOccurrencesSince(Carbon $date, Carbon $afterDate, int $count, int $skipMod, string $moment): array
{
Log::debug(sprintf('Now in %s(%s, %d, %d, %s)', __METHOD__, $date->format('Y-m-d'), $date->format('Y-m-d'), $count, $skipMod));
app('log')->debug(sprintf('Now in %s(%s, %d, %d, %s)', __METHOD__, $date->format('Y-m-d'), $date->format('Y-m-d'), $count, $skipMod));
$return = [];
$mutator = clone $date;
$total = 0;
@@ -212,19 +212,19 @@ trait CalculateXOccurrencesSince
$date = new Carbon($moment);
$date->year = $mutator->year;
if ($mutator > $date) {
Log::debug(
app('log')->debug(
sprintf('mutator (%s) > date (%s), so add a year to date (%s)', $mutator->format('Y-m-d'), $date->format('Y-m-d'), $date->format('Y-m-d'))
);
$date->addYear();
Log::debug(sprintf('Date is now %s', $date->format('Y-m-d')));
app('log')->debug(sprintf('Date is now %s', $date->format('Y-m-d')));
}
$obj = clone $date;
while ($total < $count) {
Log::debug(sprintf('total (%d) < count (%d) so go.', $total, $count));
Log::debug(sprintf('attempts (%d) %% skipmod (%d) === %d', $attempts, $skipMod, $attempts % $skipMod));
Log::debug(sprintf('Obj (%s) gte afterdate (%s)? %s', $obj->format('Y-m-d'), $afterDate->format('Y-m-d'), var_export($obj->gte($afterDate), true)));
app('log')->debug(sprintf('total (%d) < count (%d) so go.', $total, $count));
app('log')->debug(sprintf('attempts (%d) %% skipmod (%d) === %d', $attempts, $skipMod, $attempts % $skipMod));
app('log')->debug(sprintf('Obj (%s) gte afterdate (%s)? %s', $obj->format('Y-m-d'), $afterDate->format('Y-m-d'), var_export($obj->gte($afterDate), true)));
if (0 === $attempts % $skipMod && $obj->gte($afterDate)) {
Log::debug('All conditions true, add obj.');
app('log')->debug('All conditions true, add obj.');
$return[] = clone $obj;
$total++;
}

View File

@@ -45,9 +45,9 @@ trait FiltersWeekends
*/
protected function filterWeekends(RecurrenceRepetition $repetition, array $dates): array
{
Log::debug(sprintf('Now in %s', __METHOD__));
app('log')->debug(sprintf('Now in %s', __METHOD__));
if ((int)$repetition->weekend === RecurrenceRepetition::WEEKEND_DO_NOTHING) {
Log::debug('Repetition will not be filtered on weekend days.');
app('log')->debug('Repetition will not be filtered on weekend days.');
return $dates;
}
@@ -57,7 +57,7 @@ trait FiltersWeekends
$isWeekend = $date->isWeekend();
if (!$isWeekend) {
$return[] = clone $date;
//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;
}
@@ -65,7 +65,7 @@ trait FiltersWeekends
if ($repetition->weekend === RecurrenceRepetition::WEEKEND_TO_FRIDAY) {
$clone = clone $date;
$clone->addDays(5 - $date->dayOfWeekIso);
Log::debug(
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;
@@ -76,22 +76,22 @@ trait FiltersWeekends
if ($repetition->weekend === RecurrenceRepetition::WEEKEND_TO_MONDAY) {
$clone = clone $date;
$clone->addDays(8 - $date->dayOfWeekIso);
Log::debug(
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;
}
//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
Log::debug(sprintf('Count before filtering: %d', count($dates)));
app('log')->debug(sprintf('Count before filtering: %d', count($dates)));
$collection = new Collection($return);
$filtered = $collection->unique();
$return = $filtered->toArray();
Log::debug(sprintf('Count after filtering: %d', count($return)));
app('log')->debug(sprintf('Count after filtering: %d', count($return)));
return $return;
}