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

@@ -62,7 +62,7 @@ class CreateAutoBudgetLimits implements ShouldQueue
$newDate = clone $date;
$newDate->startOfDay();
$this->date = $newDate;
Log::debug(sprintf('Created new CreateAutoBudgetLimits("%s")', $this->date->format('Y-m-d')));
app('log')->debug(sprintf('Created new CreateAutoBudgetLimits("%s")', $this->date->format('Y-m-d')));
}
}
@@ -73,9 +73,9 @@ class CreateAutoBudgetLimits implements ShouldQueue
*/
public function handle(): void
{
Log::debug(sprintf('Now at start of CreateAutoBudgetLimits() job for %s.', $this->date->format('D d M Y')));
app('log')->debug(sprintf('Now at start of CreateAutoBudgetLimits() job for %s.', $this->date->format('D d M Y')));
$autoBudgets = AutoBudget::get();
Log::debug(sprintf('Found %d auto budgets.', $autoBudgets->count()));
app('log')->debug(sprintf('Found %d auto budgets.', $autoBudgets->count()));
foreach ($autoBudgets as $autoBudget) {
$this->handleAutoBudget($autoBudget);
}
@@ -110,7 +110,7 @@ class CreateAutoBudgetLimits implements ShouldQueue
$autoBudget->budget->name
)
);
Log::debug(sprintf('Done with auto budget #%d', $autoBudget->id));
app('log')->debug(sprintf('Done with auto budget #%d', $autoBudget->id));
return;
}
@@ -136,7 +136,7 @@ class CreateAutoBudgetLimits implements ShouldQueue
// that's easy: create one.
// do nothing else.
$this->createBudgetLimit($autoBudget, $start, $end);
Log::debug(sprintf('Done with auto budget #%d', $autoBudget->id));
app('log')->debug(sprintf('Done with auto budget #%d', $autoBudget->id));
return;
}
@@ -144,18 +144,18 @@ class CreateAutoBudgetLimits implements ShouldQueue
if (null === $budgetLimit && AutoBudget::AUTO_BUDGET_ROLLOVER === (int)$autoBudget->auto_budget_type) {
// budget limit exists already,
$this->createRollover($autoBudget);
Log::debug(sprintf('Done with auto budget #%d', $autoBudget->id));
app('log')->debug(sprintf('Done with auto budget #%d', $autoBudget->id));
return;
}
if (null === $budgetLimit && AutoBudget::AUTO_BUDGET_ADJUSTED === (int)$autoBudget->auto_budget_type) {
// budget limit exists already,
$this->createAdjustedLimit($autoBudget);
Log::debug(sprintf('Done with auto budget #%d', $autoBudget->id));
app('log')->debug(sprintf('Done with auto budget #%d', $autoBudget->id));
return;
}
Log::debug(sprintf('Done with auto budget #%d', $autoBudget->id));
app('log')->debug(sprintf('Done with auto budget #%d', $autoBudget->id));
}
/**
@@ -207,7 +207,7 @@ class CreateAutoBudgetLimits implements ShouldQueue
*/
private function findBudgetLimit(Budget $budget, Carbon $start, Carbon $end): ?BudgetLimit
{
Log::debug(
app('log')->debug(
sprintf(
'Going to find a budget limit for budget #%d ("%s") between %s and %s',
$budget->id,
@@ -230,9 +230,9 @@ class CreateAutoBudgetLimits implements ShouldQueue
*/
private function createBudgetLimit(AutoBudget $autoBudget, Carbon $start, Carbon $end, ?string $amount = null)
{
Log::debug(sprintf('No budget limit exist. Must create one for auto-budget #%d', $autoBudget->id));
app('log')->debug(sprintf('No budget limit exist. Must create one for auto-budget #%d', $autoBudget->id));
if (null !== $amount) {
Log::debug(sprintf('Amount is overruled and will be set to %s', $amount));
app('log')->debug(sprintf('Amount is overruled and will be set to %s', $amount));
}
$budgetLimit = new BudgetLimit();
$budgetLimit->budget()->associate($autoBudget->budget);
@@ -244,7 +244,7 @@ class CreateAutoBudgetLimits implements ShouldQueue
$budgetLimit->generated = true;
$budgetLimit->save();
Log::debug(sprintf('Created budget limit #%d.', $budgetLimit->id));
app('log')->debug(sprintf('Created budget limit #%d.', $budgetLimit->id));
}
/**
@@ -254,7 +254,7 @@ class CreateAutoBudgetLimits implements ShouldQueue
*/
private function createRollover(AutoBudget $autoBudget): void
{
Log::debug(sprintf('Will now manage rollover for auto budget #%d', $autoBudget->id));
app('log')->debug(sprintf('Will now manage rollover for auto budget #%d', $autoBudget->id));
// current period:
$start = app('navigation')->startOfPeriod($this->date, $autoBudget->period);
$end = app('navigation')->endOfPeriod($start, $autoBudget->period);
@@ -263,7 +263,7 @@ class CreateAutoBudgetLimits implements ShouldQueue
$previousStart = app('navigation')->subtractPeriod($start, $autoBudget->period);
$previousEnd = app('navigation')->endOfPeriod($previousStart, $autoBudget->period);
Log::debug(
app('log')->debug(
sprintf(
'Current period is %s-%s, so previous period is %s-%s',
$start->format('Y-m-d'),
@@ -277,27 +277,27 @@ class CreateAutoBudgetLimits implements ShouldQueue
$budgetLimit = $this->findBudgetLimit($autoBudget->budget, $previousStart, $previousEnd);
if (null === $budgetLimit) {
Log::debug('No budget limit exists in previous period, so create one.');
app('log')->debug('No budget limit exists in previous period, so create one.');
// if not, create it and we're done.
$this->createBudgetLimit($autoBudget, $start, $end);
Log::debug(sprintf('Done with auto budget #%d', $autoBudget->id));
app('log')->debug(sprintf('Done with auto budget #%d', $autoBudget->id));
return;
}
Log::debug('Budget limit exists for previous period.');
app('log')->debug('Budget limit exists for previous period.');
// if has one, calculate expenses and use that as a base.
$repository = app(OperationsRepositoryInterface::class);
$repository->setUser($autoBudget->budget->user);
$spent = $repository->sumExpenses($previousStart, $previousEnd, null, new Collection([$autoBudget->budget]), $autoBudget->transactionCurrency);
$currencyId = (int)$autoBudget->transaction_currency_id;
$spentAmount = $spent[$currencyId]['sum'] ?? '0';
Log::debug(sprintf('Spent in previous budget period (%s-%s) is %s', $previousStart->format('Y-m-d'), $previousEnd->format('Y-m-d'), $spentAmount));
app('log')->debug(sprintf('Spent in previous budget period (%s-%s) is %s', $previousStart->format('Y-m-d'), $previousEnd->format('Y-m-d'), $spentAmount));
// if you spent more in previous budget period, than whatever you had previous budget period, the amount resets
// previous budget limit + spent
$budgetLeft = bcadd($budgetLimit->amount, $spentAmount);
$totalAmount = $autoBudget->amount;
Log::debug(sprintf('Total amount left for previous budget period is %s', $budgetLeft));
app('log')->debug(sprintf('Total amount left for previous budget period is %s', $budgetLeft));
if (-1 !== bccomp('0', $budgetLeft)) {
app('log')->info(sprintf('The amount left is negative, so it will be reset to %s.', $totalAmount));
@@ -309,7 +309,7 @@ class CreateAutoBudgetLimits implements ShouldQueue
// create budget limit:
$this->createBudgetLimit($autoBudget, $start, $end, $totalAmount);
Log::debug(sprintf('Done with auto budget #%d', $autoBudget->id));
app('log')->debug(sprintf('Done with auto budget #%d', $autoBudget->id));
}
/**
@@ -319,7 +319,7 @@ class CreateAutoBudgetLimits implements ShouldQueue
*/
private function createAdjustedLimit(AutoBudget $autoBudget): void
{
Log::debug(sprintf('Will now manage rollover for auto budget #%d', $autoBudget->id));
app('log')->debug(sprintf('Will now manage rollover for auto budget #%d', $autoBudget->id));
// current period:
$start = app('navigation')->startOfPeriod($this->date, $autoBudget->period);
$end = app('navigation')->endOfPeriod($start, $autoBudget->period);
@@ -328,7 +328,7 @@ class CreateAutoBudgetLimits implements ShouldQueue
$previousStart = app('navigation')->subtractPeriod($start, $autoBudget->period);
$previousEnd = app('navigation')->endOfPeriod($previousStart, $autoBudget->period);
Log::debug(
app('log')->debug(
sprintf(
'Current period is %s-%s, so previous period is %s-%s',
$start->format('Y-m-d'),
@@ -342,12 +342,12 @@ class CreateAutoBudgetLimits implements ShouldQueue
$budgetLimit = $this->findBudgetLimit($autoBudget->budget, $previousStart, $previousEnd);
if (null === $budgetLimit) {
Log::debug('No budget limit exists in previous period, so create one.');
app('log')->debug('No budget limit exists in previous period, so create one.');
// if not, create standard amount, and we're done.
$this->createBudgetLimit($autoBudget, $start, $end);
return;
}
Log::debug('Budget limit exists for previous period.');
app('log')->debug('Budget limit exists for previous period.');
// if has one, calculate expenses and use that as a base.
$repository = app(OperationsRepositoryInterface::class);
@@ -355,14 +355,14 @@ class CreateAutoBudgetLimits implements ShouldQueue
$spent = $repository->sumExpenses($previousStart, $previousEnd, null, new Collection([$autoBudget->budget]), $autoBudget->transactionCurrency);
$currencyId = (int)$autoBudget->transaction_currency_id;
$spentAmount = $spent[$currencyId]['sum'] ?? '0';
Log::debug(sprintf('Spent in previous budget period (%s-%s) is %s', $previousStart->format('Y-m-d'), $previousEnd->format('Y-m-d'), $spentAmount));
app('log')->debug(sprintf('Spent in previous budget period (%s-%s) is %s', $previousStart->format('Y-m-d'), $previousEnd->format('Y-m-d'), $spentAmount));
// what you spent in previous period PLUS the amount for the current period,
// if that is more than zero, that's the amount that will be set.
$budgetAvailable = bcadd(bcadd($budgetLimit->amount, $autoBudget->amount), $spentAmount);
$totalAmount = $autoBudget->amount;
Log::debug(sprintf('Total amount available for current budget period is %s', $budgetAvailable));
app('log')->debug(sprintf('Total amount available for current budget period is %s', $budgetAvailable));
if (-1 !== bccomp($budgetAvailable, $totalAmount)) {
@@ -380,7 +380,7 @@ class CreateAutoBudgetLimits implements ShouldQueue
// create budget limit:
$this->createBudgetLimit($autoBudget, $start, $end, '1');
}
Log::debug(sprintf('Done with auto budget #%d', $autoBudget->id));
app('log')->debug(sprintf('Done with auto budget #%d', $autoBudget->id));
}
/**

View File

@@ -93,7 +93,7 @@ class CreateRecurringTransactions implements ShouldQueue
$this->recurrences = new Collection();
$this->groups = new Collection();
Log::debug(sprintf('Created new CreateRecurringTransactions("%s")', $this->date->format('Y-m-d')));
app('log')->debug(sprintf('Created new CreateRecurringTransactions("%s")', $this->date->format('Y-m-d')));
}
/**
@@ -109,25 +109,25 @@ class CreateRecurringTransactions implements ShouldQueue
*/
public function handle(): void
{
Log::debug(sprintf('Now at start of CreateRecurringTransactions() job for %s.', $this->date->format('D d M Y')));
app('log')->debug(sprintf('Now at start of CreateRecurringTransactions() job for %s.', $this->date->format('D d M Y')));
// only use recurrences from database if there is no collection submitted.
if (0 !== count($this->recurrences)) {
Log::debug('Using predetermined set of recurrences.');
app('log')->debug('Using predetermined set of recurrences.');
}
if (0 === count($this->recurrences)) {
Log::debug('Grab all recurrences from the database.');
app('log')->debug('Grab all recurrences from the database.');
$this->recurrences = $this->repository->getAll();
}
$result = [];
$count = $this->recurrences->count();
$this->submitted = $count;
Log::debug(sprintf('Count of collection is %d', $count));
app('log')->debug(sprintf('Count of collection is %d', $count));
// filter recurrences:
$filtered = $this->filterRecurrences($this->recurrences);
Log::debug(sprintf('Left after filtering is %d', $filtered->count()));
app('log')->debug(sprintf('Left after filtering is %d', $filtered->count()));
/** @var Recurrence $recurrence */
foreach ($filtered as $recurrence) {
if (!array_key_exists($recurrence->user_id, $result)) {
@@ -140,20 +140,20 @@ class CreateRecurringTransactions implements ShouldQueue
// clear cache for user
app('preferences')->setForUser($recurrence->user, 'lastActivity', microtime());
Log::debug(sprintf('Now at recurrence #%d of user #%d', $recurrence->id, $recurrence->user_id));
app('log')->debug(sprintf('Now at recurrence #%d of user #%d', $recurrence->id, $recurrence->user_id));
$createdReps = $this->handleRepetitions($recurrence);
Log::debug(sprintf('Done with recurrence #%d', $recurrence->id));
app('log')->debug(sprintf('Done with recurrence #%d', $recurrence->id));
$result[$recurrence->user_id] = $result[$recurrence->user_id]->merge($createdReps);
$this->executed++;
}
Log::debug('Now running report thing.');
app('log')->debug('Now running report thing.');
// will now send email to users.
foreach ($result as $userId => $journals) {
event(new RequestedReportOnJournals($userId, $journals));
}
Log::debug('Done with handle()');
app('log')->debug('Done with handle()');
// clear cache:
app('preferences')->mark();
@@ -183,7 +183,7 @@ class CreateRecurringTransactions implements ShouldQueue
*/
private function validRecurrence(Recurrence $recurrence): bool
{
Log::debug(sprintf('Now filtering recurrence #%d, owned by user #%d', $recurrence->id, $recurrence->user_id));
app('log')->debug(sprintf('Now filtering recurrence #%d, owned by user #%d', $recurrence->id, $recurrence->user_id));
// is not active.
if (!$this->active($recurrence)) {
app('log')->info(sprintf('Recurrence #%d is not active. Skipped.', $recurrence->id));
@@ -233,7 +233,7 @@ class CreateRecurringTransactions implements ShouldQueue
return false;
}
Log::debug('Will be included.');
app('log')->debug('Will be included.');
return true;
}
@@ -273,7 +273,7 @@ class CreateRecurringTransactions implements ShouldQueue
private function hasNotStartedYet(Recurrence $recurrence): bool
{
$startDate = $this->getStartDate($recurrence);
Log::debug(sprintf('Start date is %s', $startDate->format('Y-m-d')));
app('log')->debug(sprintf('Start date is %s', $startDate->format('Y-m-d')));
return $startDate->gt($this->date);
}
@@ -322,7 +322,7 @@ class CreateRecurringTransactions implements ShouldQueue
$collection = new Collection();
/** @var RecurrenceRepetition $repetition */
foreach ($recurrence->recurrenceRepetitions as $repetition) {
Log::debug(
app('log')->debug(
sprintf(
'Now repeating %s with value "%s", skips every %d time(s)',
$repetition->repetition_type,
@@ -386,7 +386,7 @@ class CreateRecurringTransactions implements ShouldQueue
if ($date->ne($this->date)) {
return null;
}
Log::debug(sprintf('%s IS today (%s)', $date->format('Y-m-d'), $this->date->format('Y-m-d')));
app('log')->debug(sprintf('%s IS today (%s)', $date->format('Y-m-d'), $this->date->format('Y-m-d')));
// count created journals on THIS day.
$journalCount = $this->repository->getJournalCount($recurrence, $date, $date);

View File

@@ -74,7 +74,7 @@ class DownloadExchangeRates implements ShouldQueue
$newDate = clone $date;
$newDate->startOfDay();
$this->date = $newDate;
Log::debug(sprintf('Created new DownloadExchangeRates("%s")', $this->date->format('Y-m-d')));
app('log')->debug(sprintf('Created new DownloadExchangeRates("%s")', $this->date->format('Y-m-d')));
}
}
@@ -83,7 +83,7 @@ class DownloadExchangeRates implements ShouldQueue
*/
public function handle(): void
{
Log::debug('Now in handle()');
app('log')->debug('Now in handle()');
$currencies = $this->repository->getCompleteSet();
/** @var TransactionCurrency $currency */
@@ -100,7 +100,7 @@ class DownloadExchangeRates implements ShouldQueue
*/
private function downloadRates(TransactionCurrency $currency): void
{
Log::debug(sprintf('Now downloading new exchange rates for currency %s.', $currency->code));
app('log')->debug(sprintf('Now downloading new exchange rates for currency %s.', $currency->code));
$base = sprintf('%s/%s/%s', (string)config('cer.url'), $this->date->year, $this->date->isoWeek);
$client = new Client();
$url = sprintf('%s/%s.json', $base, $currency->code);
@@ -137,10 +137,10 @@ class DownloadExchangeRates implements ShouldQueue
foreach ($rates as $code => $rate) {
$to = $this->getCurrency($code);
if (null === $to) {
Log::debug(sprintf('Currency %s is not in use, do not save rate.', $code));
app('log')->debug(sprintf('Currency %s is not in use, do not save rate.', $code));
continue;
}
Log::debug(sprintf('Currency %s is in use.', $code));
app('log')->debug(sprintf('Currency %s is in use.', $code));
$this->saveRate($currency, $to, $date, $rate);
}
}
@@ -154,22 +154,22 @@ class DownloadExchangeRates implements ShouldQueue
{
// if we have it already, don't bother searching for it again.
if (array_key_exists($code, $this->active)) {
Log::debug(sprintf('Already know what the result is of searching for %s', $code));
app('log')->debug(sprintf('Already know what the result is of searching for %s', $code));
return $this->active[$code];
}
// find it in the database.
$currency = $this->repository->findByCode($code);
if (null === $currency) {
Log::debug(sprintf('Did not find currency %s.', $code));
app('log')->debug(sprintf('Did not find currency %s.', $code));
$this->active[$code] = null;
return null;
}
if (false === $currency->enabled) {
Log::debug(sprintf('Currency %s is not enabled.', $code));
app('log')->debug(sprintf('Currency %s is not enabled.', $code));
$this->active[$code] = null;
return null;
}
Log::debug(sprintf('Currency %s is enabled.', $code));
app('log')->debug(sprintf('Currency %s is enabled.', $code));
$this->active[$code] = $currency;
return $currency;
@@ -189,7 +189,7 @@ class DownloadExchangeRates implements ShouldQueue
$this->repository->setUser($user);
$existing = $this->repository->getExchangeRate($from, $to, $date);
if (null === $existing) {
Log::debug(sprintf('Saved rate from %s to %s for user #%d.', $from->code, $to->code, $user->id));
app('log')->debug(sprintf('Saved rate from %s to %s for user #%d.', $from->code, $to->code, $user->id));
$this->repository->setExchangeRate($from, $to, $date, $rate);
}
}

View File

@@ -62,7 +62,7 @@ class SendWebhookMessage implements ShouldQueue
*/
public function handle(): void
{
Log::debug(sprintf('Now handling webhook message #%d', $this->message->id));
app('log')->debug(sprintf('Now handling webhook message #%d', $this->message->id));
// send job!
$sender = app(WebhookSenderInterface::class);
$sender->setMessage($this->message);

View File

@@ -67,7 +67,7 @@ class WarnAboutBills implements ShouldQueue
$this->force = false;
Log::debug(sprintf('Created new WarnAboutBills("%s")', $this->date->format('Y-m-d')));
app('log')->debug(sprintf('Created new WarnAboutBills("%s")', $this->date->format('Y-m-d')));
}
/**
@@ -75,11 +75,11 @@ class WarnAboutBills implements ShouldQueue
*/
public function handle(): void
{
Log::debug(sprintf('Now at start of WarnAboutBills() job for %s.', $this->date->format('D d M Y')));
app('log')->debug(sprintf('Now at start of WarnAboutBills() job for %s.', $this->date->format('D d M Y')));
$bills = Bill::all();
/** @var Bill $bill */
foreach ($bills as $bill) {
Log::debug(sprintf('Now checking bill #%d ("%s")', $bill->id, $bill->name));
app('log')->debug(sprintf('Now checking bill #%d ("%s")', $bill->id, $bill->name));
if ($this->hasDateFields($bill)) {
if ($this->needsWarning($bill, 'end_date')) {
$this->sendWarning($bill, 'end_date');
@@ -89,7 +89,7 @@ class WarnAboutBills implements ShouldQueue
}
}
}
Log::debug('Done with handle()');
app('log')->debug('Done with handle()');
// clear cache:
app('preferences')->mark();
@@ -103,11 +103,11 @@ class WarnAboutBills implements ShouldQueue
private function hasDateFields(Bill $bill): bool
{
if (false === $bill->active) {
Log::debug('Bill is not active.');
app('log')->debug('Bill is not active.');
return false;
}
if (null === $bill->end_date && null === $bill->extension_date) {
Log::debug('Bill has no date fields.');
app('log')->debug('Bill has no date fields.');
return false;
}
return true;
@@ -126,7 +126,7 @@ class WarnAboutBills implements ShouldQueue
}
$diff = $this->getDiff($bill, $field);
$list = config('firefly.bill_reminder_periods');
Log::debug(sprintf('Difference in days for field "%s" ("%s") is %d day(s)', $field, $bill->$field->format('Y-m-d'), $diff));
app('log')->debug(sprintf('Difference in days for field "%s" ("%s") is %d day(s)', $field, $bill->$field->format('Y-m-d'), $diff));
if (in_array($diff, $list, true)) {
return true;
}
@@ -155,7 +155,7 @@ class WarnAboutBills implements ShouldQueue
private function sendWarning(Bill $bill, string $field): void
{
$diff = $this->getDiff($bill, $field);
Log::debug('Will now send warning!');
app('log')->debug('Will now send warning!');
event(new WarnUserAboutBill($bill, $field, $diff));
}