From b2d4469908f25329e99b5e74f5c3211a68b41b1f Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 6 Nov 2024 12:01:29 +0100 Subject: [PATCH] Mild code cleanup. --- .../Events/Model/PiggyBankEventHandler.php | 2 +- app/Handlers/Observer/PiggyBankObserver.php | 4 ++-- .../Recurring/TriggerController.php | 12 ++++++------ app/Jobs/CreateRecurringTransactions.php | 14 +++++++------- app/Models/AccountBalance.php | 2 +- app/Models/AvailableBudget.php | 2 +- app/Models/BudgetLimit.php | 2 +- app/Models/CurrencyExchangeRate.php | 2 +- app/Models/InvitedUser.php | 2 +- app/Models/PiggyBank.php | 2 +- app/Models/PiggyBankEvent.php | 2 +- app/Models/PiggyBankRepetition.php | 2 +- app/Models/Recurrence.php | 2 +- app/Models/Tag.php | 2 +- .../PiggyBank/ModifiesPiggyBanks.php | 18 +++++++++--------- app/Repositories/User/UserRepository.php | 2 +- app/Rules/Account/IsUniqueAccount.php | 1 + .../Update/RecurrenceUpdateService.php | 6 +++--- 18 files changed, 40 insertions(+), 39 deletions(-) diff --git a/app/Handlers/Events/Model/PiggyBankEventHandler.php b/app/Handlers/Events/Model/PiggyBankEventHandler.php index ea4bb49a2e..dfa4762fcb 100644 --- a/app/Handlers/Events/Model/PiggyBankEventHandler.php +++ b/app/Handlers/Events/Model/PiggyBankEventHandler.php @@ -58,7 +58,7 @@ class PiggyBankEventHandler 'piggy_bank_id' => $event->piggyBank->id, 'transaction_journal_id' => $journal?->id, 'date' => $date->format('Y-m-d'), - 'date_tz' => $date->format('e'), + 'date_tz' => $date->format('e'), 'amount' => $event->amount, ] ); diff --git a/app/Handlers/Observer/PiggyBankObserver.php b/app/Handlers/Observer/PiggyBankObserver.php index d8e93364ff..4a45ee3f47 100644 --- a/app/Handlers/Observer/PiggyBankObserver.php +++ b/app/Handlers/Observer/PiggyBankObserver.php @@ -37,9 +37,9 @@ class PiggyBankObserver $repetition = new PiggyBankRepetition(); $repetition->piggyBank()->associate($piggyBank); $repetition->startdate = $piggyBank->startdate; - $repetition->startdate_tz = $piggyBank->startdate->format('e'); + $repetition->startdate_tz = $piggyBank->startdate->format('e'); $repetition->targetdate = $piggyBank->targetdate; - $repetition->targetdate_tz = $piggyBank->targetdate->format('e'); + $repetition->targetdate_tz = $piggyBank->targetdate->format('e'); $repetition->currentamount = '0'; $repetition->save(); } diff --git a/app/Http/Controllers/Recurring/TriggerController.php b/app/Http/Controllers/Recurring/TriggerController.php index d8483b84df..e1a4c3be79 100644 --- a/app/Http/Controllers/Recurring/TriggerController.php +++ b/app/Http/Controllers/Recurring/TriggerController.php @@ -40,24 +40,24 @@ class TriggerController extends Controller { public function trigger(Recurrence $recurrence, TriggerRecurrenceRequest $request): RedirectResponse { - $all = $request->getAll(); - $date = $all['date']; + $all = $request->getAll(); + $date = $all['date']; // grab the date from the last time the recurrence fired: - $backupDate = $recurrence->latest_date; + $backupDate = $recurrence->latest_date; // fire the recurring cron job on the given date, then post-date the created transaction. app('log')->info(sprintf('Trigger: will now fire recurring cron job task for date "%s".', $date->format('Y-m-d H:i:s'))); /** @var CreateRecurringTransactions $job */ - $job = app(CreateRecurringTransactions::class); + $job = app(CreateRecurringTransactions::class); $job->setRecurrences(new Collection([$recurrence])); $job->setDate($date); $job->setForce(false); $job->handle(); app('log')->debug('Done with recurrence.'); - $groups = $job->getGroups(); + $groups = $job->getGroups(); /** @var TransactionGroup $group */ foreach ($groups as $group) { @@ -68,7 +68,7 @@ class TriggerController extends Controller $journal->save(); } } - $recurrence->latest_date = $backupDate; + $recurrence->latest_date = $backupDate; $recurrence->latest_date_tz = $backupDate?->format('e'); $recurrence->save(); app('preferences')->mark(); diff --git a/app/Jobs/CreateRecurringTransactions.php b/app/Jobs/CreateRecurringTransactions.php index 05147b4b48..9cdcaead73 100644 --- a/app/Jobs/CreateRecurringTransactions.php +++ b/app/Jobs/CreateRecurringTransactions.php @@ -343,7 +343,7 @@ class CreateRecurringTransactions implements ShouldQueue 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); + $journalCount = $this->repository->getJournalCount($recurrence, $date, $date); if ($journalCount > 0 && false === $this->force) { app('log')->info(sprintf('Already created %d journal(s) for date %s', $journalCount, $date->format('Y-m-d'))); @@ -361,11 +361,11 @@ class CreateRecurringTransactions implements ShouldQueue } // create transaction array and send to factory. - $groupTitle = null; - $count = $recurrence->recurrenceTransactions->count(); + $groupTitle = null; + $count = $recurrence->recurrenceTransactions->count(); // #8844, if there is one recurrence transaction, use the first title as the title. // #9305, if there is one recurrence transaction, group title must be NULL. - $groupTitle = null; + $groupTitle = null; // #8844, if there are more, use the recurrence transaction itself. if ($count > 1) { @@ -378,14 +378,14 @@ class CreateRecurringTransactions implements ShouldQueue return null; } - $array = [ + $array = [ 'user' => $recurrence->user_id, 'group_title' => $groupTitle, 'transactions' => $this->getTransactionData($recurrence, $repetition, $date), ]; /** @var TransactionGroup $group */ - $group = $this->groupRepository->store($array); + $group = $this->groupRepository->store($array); ++$this->created; app('log')->info(sprintf('Created new transaction group #%d', $group->id)); @@ -394,7 +394,7 @@ class CreateRecurringTransactions implements ShouldQueue $this->groups->push($group); // update recurring thing: - $recurrence->latest_date = $date; + $recurrence->latest_date = $date; $recurrence->latest_date_tz = $date?->format('e'); $recurrence->save(); diff --git a/app/Models/AccountBalance.php b/app/Models/AccountBalance.php index 0d05c02d63..baa996167d 100644 --- a/app/Models/AccountBalance.php +++ b/app/Models/AccountBalance.php @@ -14,7 +14,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; class AccountBalance extends Model { use HasFactory; - protected $fillable = ['account_id', 'title', 'transaction_currency_id', 'balance','date','date_tz']; + protected $fillable = ['account_id', 'title', 'transaction_currency_id', 'balance', 'date', 'date_tz']; public function account(): BelongsTo { diff --git a/app/Models/AvailableBudget.php b/app/Models/AvailableBudget.php index 7b44159630..f2c54a1263 100644 --- a/app/Models/AvailableBudget.php +++ b/app/Models/AvailableBudget.php @@ -51,7 +51,7 @@ class AvailableBudget extends Model 'transaction_currency_id' => 'int', ]; - protected $fillable = ['user_id', 'user_group_id', 'transaction_currency_id', 'amount', 'start_date', 'end_date', 'start_date_tz','end_date_tz']; + protected $fillable = ['user_id', 'user_group_id', 'transaction_currency_id', 'amount', 'start_date', 'end_date', 'start_date_tz', 'end_date_tz']; /** * Route binder. Converts the key in the URL to the specified object (or throw 404). diff --git a/app/Models/BudgetLimit.php b/app/Models/BudgetLimit.php index d4375cc8a7..1fafd7f2e6 100644 --- a/app/Models/BudgetLimit.php +++ b/app/Models/BudgetLimit.php @@ -54,7 +54,7 @@ class BudgetLimit extends Model 'deleted' => Deleted::class, ]; - protected $fillable = ['budget_id', 'start_date', 'end_date','start_date_tz','end_date_tz', 'amount', 'transaction_currency_id']; + protected $fillable = ['budget_id', 'start_date', 'end_date', 'start_date_tz', 'end_date_tz', 'amount', 'transaction_currency_id']; /** * Route binder. Converts the key in the URL to the specified object (or throw 404). diff --git a/app/Models/CurrencyExchangeRate.php b/app/Models/CurrencyExchangeRate.php index 88cbb9ecb3..3cb848bdf0 100644 --- a/app/Models/CurrencyExchangeRate.php +++ b/app/Models/CurrencyExchangeRate.php @@ -49,7 +49,7 @@ class CurrencyExchangeRate extends Model 'to_currency_id' => 'int', 'date' => 'datetime', ]; - protected $fillable = ['user_id', 'from_currency_id', 'to_currency_id', 'date','date_tz', 'rate']; + protected $fillable = ['user_id', 'from_currency_id', 'to_currency_id', 'date', 'date_tz', 'rate']; public function fromCurrency(): BelongsTo { diff --git a/app/Models/InvitedUser.php b/app/Models/InvitedUser.php index 9501f137d9..3360413df0 100644 --- a/app/Models/InvitedUser.php +++ b/app/Models/InvitedUser.php @@ -44,7 +44,7 @@ class InvitedUser extends Model 'expires' => 'datetime', 'redeemed' => 'boolean', ]; - protected $fillable = ['user_id', 'email', 'invite_code', 'expires','expires_tz', 'redeemed']; + protected $fillable = ['user_id', 'email', 'invite_code', 'expires', 'expires_tz', 'redeemed']; /** * Route binder. Converts the key in the URL to the specified object (or throw 404). diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php index 3b9fe5a0ef..bd65c314ec 100644 --- a/app/Models/PiggyBank.php +++ b/app/Models/PiggyBank.php @@ -53,7 +53,7 @@ class PiggyBank extends Model 'encrypted' => 'boolean', ]; - protected $fillable = ['name', 'account_id', 'order', 'targetamount', 'startdate','startdate_tz', 'targetdate', 'targetdate_tz', 'active']; + protected $fillable = ['name', 'account_id', 'order', 'targetamount', 'startdate', 'startdate_tz', 'targetdate', 'targetdate_tz', 'active']; protected $hidden = ['targetamount_encrypted', 'encrypted']; diff --git a/app/Models/PiggyBankEvent.php b/app/Models/PiggyBankEvent.php index 813e5e4517..9dc798ab96 100644 --- a/app/Models/PiggyBankEvent.php +++ b/app/Models/PiggyBankEvent.php @@ -42,7 +42,7 @@ class PiggyBankEvent extends Model 'date' => 'date', ]; - protected $fillable = ['piggy_bank_id', 'transaction_journal_id', 'date', 'date_tz','amount']; + protected $fillable = ['piggy_bank_id', 'transaction_journal_id', 'date', 'date_tz', 'amount']; protected $hidden = ['amount_encrypted']; diff --git a/app/Models/PiggyBankRepetition.php b/app/Models/PiggyBankRepetition.php index 01df565ff4..5c20d75baa 100644 --- a/app/Models/PiggyBankRepetition.php +++ b/app/Models/PiggyBankRepetition.php @@ -45,7 +45,7 @@ class PiggyBankRepetition extends Model 'targetdate' => 'date', ]; - protected $fillable = ['piggy_bank_id', 'startdate','startdate_tz', 'targetdate','targetdate_tz', 'currentamount']; + protected $fillable = ['piggy_bank_id', 'startdate', 'startdate_tz', 'targetdate', 'targetdate_tz', 'currentamount']; public function piggyBank(): BelongsTo { diff --git a/app/Models/Recurrence.php b/app/Models/Recurrence.php index 2ba068135f..61b96fe68e 100644 --- a/app/Models/Recurrence.php +++ b/app/Models/Recurrence.php @@ -60,7 +60,7 @@ class Recurrence extends Model ]; protected $fillable - = ['user_id', 'transaction_type_id', 'title', 'description', 'first_date','first_date_tz', 'repeat_until','repeat_until_tz', 'latest_date','latest_date_tz', 'repetitions', 'apply_rules', 'active']; + = ['user_id', 'transaction_type_id', 'title', 'description', 'first_date', 'first_date_tz', 'repeat_until', 'repeat_until_tz', 'latest_date', 'latest_date_tz', 'repetitions', 'apply_rules', 'active']; /** @var string The table to store the data in */ protected $table = 'recurrences'; diff --git a/app/Models/Tag.php b/app/Models/Tag.php index 7eda1f1e91..f55b989e0b 100644 --- a/app/Models/Tag.php +++ b/app/Models/Tag.php @@ -53,7 +53,7 @@ class Tag extends Model 'longitude' => 'float', ]; - protected $fillable = ['user_id', 'user_group_id', 'tag', 'date','date_tz', 'description', 'tagMode']; + protected $fillable = ['user_id', 'user_group_id', 'tag', 'date', 'date_tz', 'description', 'tagMode']; protected $hidden = ['zoomLevel', 'latitude', 'longitude']; diff --git a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php index dfddb6a88a..7fa1c4c42d 100644 --- a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php +++ b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php @@ -178,12 +178,12 @@ trait ModifiesPiggyBanks */ public function store(array $data): PiggyBank { - $order = $this->getMaxOrder() + 1; + $order = $this->getMaxOrder() + 1; if (array_key_exists('order', $data)) { $order = $data['order']; } - $data['order'] = 31337; // very high when creating. - $piggyData = $data; + $data['order'] = 31337; // very high when creating. + $piggyData = $data; // unset fields just in case. unset($piggyData['object_group_title'], $piggyData['object_group_id'], $piggyData['notes'], $piggyData['current_amount']); @@ -192,7 +192,7 @@ trait ModifiesPiggyBanks $piggyData['targetamount'] = '0'; } - $piggyData['startdate_tz'] = $piggyData['startdate']?->format('e'); + $piggyData['startdate_tz'] = $piggyData['startdate']?->format('e'); $piggyData['targetdate_tz'] = $piggyData['targetdate']?->format('e'); try { @@ -211,13 +211,13 @@ trait ModifiesPiggyBanks $this->updateNote($piggyBank, $data['notes']); // repetition is auto created. - $repetition = $this->getRepetition($piggyBank); + $repetition = $this->getRepetition($piggyBank); if (null !== $repetition && array_key_exists('current_amount', $data) && '' !== $data['current_amount']) { $repetition->currentamount = $data['current_amount']; $repetition->save(); } - $objectGroupTitle = $data['object_group_title'] ?? ''; + $objectGroupTitle = $data['object_group_title'] ?? ''; if ('' !== $objectGroupTitle) { $objectGroup = $this->findOrCreateObjectGroup($objectGroupTitle); if (null !== $objectGroup) { @@ -226,7 +226,7 @@ trait ModifiesPiggyBanks } } // try also with ID - $objectGroupId = (int)($data['object_group_id'] ?? 0); + $objectGroupId = (int)($data['object_group_id'] ?? 0); if (0 !== $objectGroupId) { $objectGroup = $this->findObjectGroupById($objectGroupId); if (null !== $objectGroup) { @@ -376,11 +376,11 @@ trait ModifiesPiggyBanks $piggyBank->targetamount = '0'; } if (array_key_exists('targetdate', $data) && '' !== $data['targetdate']) { - $piggyBank->targetdate = $data['targetdate']; + $piggyBank->targetdate = $data['targetdate']; $piggyBank->targetdate_tz = $data['targetdate']->format('e'); } if (array_key_exists('startdate', $data)) { - $piggyBank->startdate = $data['startdate']; + $piggyBank->startdate = $data['startdate']; $piggyBank->startdate_tz = $data['targetdate']->format('e'); } $piggyBank->save(); diff --git a/app/Repositories/User/UserRepository.php b/app/Repositories/User/UserRepository.php index 37c699d0f5..59b96f40a6 100644 --- a/app/Repositories/User/UserRepository.php +++ b/app/Repositories/User/UserRepository.php @@ -276,7 +276,7 @@ class UserRepository implements UserRepositoryInterface $invitee->email = $email; $invitee->redeemed = false; $invitee->expires = $now; - $invitee->expires_tz = $now->format('e'); + $invitee->expires_tz = $now->format('e'); $invitee->save(); return $invitee; diff --git a/app/Rules/Account/IsUniqueAccount.php b/app/Rules/Account/IsUniqueAccount.php index d485bd2911..1a4b1eb1d0 100644 --- a/app/Rules/Account/IsUniqueAccount.php +++ b/app/Rules/Account/IsUniqueAccount.php @@ -109,6 +109,7 @@ class IsUniqueAccount implements ValidationRule, DataAwareRule { if (!array_key_exists('user_id', $this->data)) { $this->fail('No user ID provided.'); + return false; } diff --git a/app/Services/Internal/Update/RecurrenceUpdateService.php b/app/Services/Internal/Update/RecurrenceUpdateService.php index fc2dd43c27..58e81fc1ce 100644 --- a/app/Services/Internal/Update/RecurrenceUpdateService.php +++ b/app/Services/Internal/Update/RecurrenceUpdateService.php @@ -64,13 +64,13 @@ class RecurrenceUpdateService $recurrence->description = $info['description']; } if (array_key_exists('first_date', $info)) { - $recurrence->first_date = $info['first_date']; + $recurrence->first_date = $info['first_date']; $recurrence->first_date_tz = $info['first_date']?->format('e'); } if (array_key_exists('repeat_until', $info)) { - $recurrence->repeat_until = $info['repeat_until']; + $recurrence->repeat_until = $info['repeat_until']; $recurrence->repeat_until_tz = $info['repeat_until']?->format('e'); - $recurrence->repetitions = 0; + $recurrence->repetitions = 0; } if (array_key_exists('nr_of_repetitions', $info)) { if (0 !== (int)$info['nr_of_repetitions']) {