Fix sloppy variable names

This commit is contained in:
James Cole
2022-10-02 20:23:11 +02:00
parent 6dfe93bc19
commit 536e054961
19 changed files with 85 additions and 85 deletions

View File

@@ -73,10 +73,10 @@ class AddTag implements ActionInterface
// add to journal:
DB::table('tag_transaction_journal')->insert(['tag_id' => $tag->id, 'transaction_journal_id' => $journal['transaction_journal_id']]);
Log::debug(sprintf('RuleAction AddTag. Added tag #%d ("%s") to journal %d.', $tag->id, $tag->tag, $journal['transaction_journal_id']));
$journal = TransactionJournal::find($journal['transaction_journal_id']);
$object = TransactionJournal::find($journal['transaction_journal_id']);
// event for audit log entry
event(new TriggeredAuditLog($this->action->rule, $journal, 'add_tag', null, $tag->tag));
event(new TriggeredAuditLog($this->action->rule, $object, 'add_tag', null, $tag->tag));
return true;
}

View File

@@ -53,9 +53,9 @@ class AppendDescription implements ActionInterface
DB::table('transaction_journals')->where('id', $journal['transaction_journal_id'])->limit(1)->update(['description' => $description]);
// event for audit log entry
/** @var TransactionJournal $journal */
$journal = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
event(new TriggeredAuditLog($this->action->rule, $journal, 'update_description', $journal['description'], $description));
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
event(new TriggeredAuditLog($this->action->rule, $object, 'update_description', $journal['description'], $description));
return true;
}

View File

@@ -48,28 +48,28 @@ class AppendDescriptionToNotes implements ActionInterface
public function actOnArray(array $journal): bool
{
/** @var TransactionJournal $journal */
$journal = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
if (null === $journal) {
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
if (null === $object) {
Log::error(sprintf('No journal #%d belongs to user #%d.', $journal['transaction_journal_id'], $journal['user_id']));
return false;
}
$note = $journal->notes()->first();
$note = $object->notes()->first();
if (null === $note) {
$note = new Note;
$note->noteable()->associate($journal);
$note->noteable()->associate($object);
$note->text = '';
}
$before = $note->text;
if ('' !== $note->text) {
$note->text = trim(sprintf("%s \n%s", $note->text, $journal->description));
$note->text = trim(sprintf("%s \n%s", $note->text, $object->description));
}
if ('' === $note->text) {
$note->text = (string) $journal->description;
$note->text = (string) $object->description;
}
$after = $note->text;
// event for audit log entry
event(new TriggeredAuditLog($this->action->rule, $journal, 'update_notes', $before, $after));
event(new TriggeredAuditLog($this->action->rule, $object, 'update_notes', $before, $after));
$note->save();
return true;

View File

@@ -67,10 +67,10 @@ class AppendNotes implements ActionInterface
$dbNote->text = $text;
$dbNote->save();
/** @var TransactionJournal $journal */
$journal = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
event(new TriggeredAuditLog($this->action->rule, $journal, 'update_notes', $before, $text));
event(new TriggeredAuditLog($this->action->rule, $object, 'update_notes', $before, $text));
return true;
}

View File

@@ -54,27 +54,27 @@ class AppendNotesToDescription implements ActionInterface
public function actOnArray(array $journal): bool
{
Log::debug('Now in AppendNotesToDescription');
/** @var TransactionJournal $journal */
$journal = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
if (null === $journal) {
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
if (null === $object) {
Log::error(sprintf('No journal #%d belongs to user #%d.', $journal['transaction_journal_id'], $journal['user_id']));
return false;
}
$note = $journal->notes()->first();
$note = $object->notes()->first();
if (null === $note) {
Log::debug('Journal has no notes.');
$note = new Note;
$note->noteable()->associate($journal);
$note->noteable()->associate($object);
$note->text = '';
}
// only append if there is something to append
if ('' !== $note->text) {
$before = $journal->description;
$journal->description = trim(sprintf("%s %s", $journal->description, (string) $this->clearString($note->text, false)));
$journal->save();
Log::debug(sprintf('Journal description is updated to "%s".', $journal->description));
$before = $object->description;
$object->description = trim(sprintf("%s %s", $object->description, (string) $this->clearString($note->text, false)));
$object->save();
Log::debug(sprintf('Journal description is updated to "%s".', $object->description));
event(new TriggeredAuditLog($this->action->rule, $journal, 'update_description', $before, $journal->description));
event(new TriggeredAuditLog($this->action->rule, $object, 'update_description', $before, $object->description));
return true;
}

View File

@@ -51,9 +51,9 @@ class ClearBudget implements ActionInterface
*/
public function actOnArray(array $journal): bool
{
/** @var TransactionJournal $journal */
$journal = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$budget = $journal->budgets()->first();
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$budget = $object->budgets()->first();
if (null === $budget) {
Log::debug(sprintf('RuleAction ClearBudget, no budget in journal #%d.', $journal['transaction_journal_id']));
return false;
@@ -61,7 +61,7 @@ class ClearBudget implements ActionInterface
DB::table('budget_transaction_journal')->where('transaction_journal_id', '=', $journal['transaction_journal_id'])->delete();
event(new TriggeredAuditLog($this->action->rule, $journal, 'clear_budget', $budget->name, null));
event(new TriggeredAuditLog($this->action->rule, $object, 'clear_budget', $budget->name, null));
Log::debug(sprintf('RuleAction ClearBudget removed all budgets from journal #%d.', $journal['transaction_journal_id']));

View File

@@ -50,9 +50,9 @@ class ClearCategory implements ActionInterface
*/
public function actOnArray(array $journal): bool
{
/** @var TransactionJournal $journal */
$journal = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$category = $journal->categories()->first();
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$category = $object->categories()->first();
if (null === $category) {
Log::debug(sprintf('RuleAction ClearCategory, no category in journal #%d.', $journal['transaction_journal_id']));
return false;
@@ -60,7 +60,7 @@ class ClearCategory implements ActionInterface
DB::table('category_transaction_journal')->where('transaction_journal_id', '=', $journal['transaction_journal_id'])->delete();
event(new TriggeredAuditLog($this->action->rule, $journal, 'clear_category', $category->name, null));
event(new TriggeredAuditLog($this->action->rule, $object, 'clear_category', $category->name, null));
Log::debug(sprintf('RuleAction ClearCategory removed all categories from journal #%d.', $journal['transaction_journal_id']));

View File

@@ -50,8 +50,8 @@ class ClearNotes implements ActionInterface
*/
public function actOnArray(array $journal): bool
{
$journal = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$notes = $journal->notes()->first();
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$notes = $object->notes()->first();
if (null === $notes) {
Log::debug(sprintf('RuleAction ClearNotes, journal #%d has no notes.', $journal['transaction_journal_id']));
return false;
@@ -64,7 +64,7 @@ class ClearNotes implements ActionInterface
->delete();
Log::debug(sprintf('RuleAction ClearNotes removed all notes from journal #%d.', $journal['transaction_journal_id']));
event(new TriggeredAuditLog($this->action->rule, $journal, 'clear_notes', $before, null));
event(new TriggeredAuditLog($this->action->rule, $object, 'clear_notes', $before, null));
return true;
}

View File

@@ -75,12 +75,12 @@ class DeleteTransaction implements ActionInterface
);
// trigger delete factory:
$journal = TransactionJournal::find($journal['transaction_group_id']);
if (null !== $journal) {
$object = TransactionJournal::find($journal['transaction_group_id']);
if (null !== $object) {
/** @var JournalDestroyService $service */
$service = app(JournalDestroyService::class);
$service->destroy($journal);
event(new TriggeredAuditLog($this->action->rule, $journal, 'delete_journal', null, null));
$service->destroy($object);
event(new TriggeredAuditLog($this->action->rule, $object, 'delete_journal', null, null));
}
return true;

View File

@@ -78,8 +78,8 @@ class LinkToBill implements ActionInterface
sprintf('RuleAction LinkToBill set the bill of journal #%d to bill #%d ("%s").', $journal['transaction_journal_id'], $bill->id, $bill->name)
);
$journal = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
event(new TriggeredAuditLog($this->action->rule, $journal, 'set_bill', null, $bill->name));
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
event(new TriggeredAuditLog($this->action->rule, $object, 'set_bill', null, $bill->name));
return true;
}

View File

@@ -52,35 +52,35 @@ class MoveDescriptionToNotes implements ActionInterface
*/
public function actOnArray(array $journal): bool
{
/** @var TransactionJournal $journal */
$journal = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
if (null === $journal) {
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
if (null === $object) {
Log::error(sprintf('No journal #%d belongs to user #%d.', $journal['transaction_journal_id'], $journal['user_id']));
return false;
}
$note = $journal->notes()->first();
$note = $object->notes()->first();
if (null === $note) {
$note = new Note;
$note->noteable()->associate($journal);
$note->noteable()->associate($object);
$note->text = '';
}
$before = $note->text;
$beforeDescription = $journal->description;
$beforeDescription = $object->description;
if ('' !== $note->text) {
$note->text = trim(sprintf("%s \n%s", $note->text, $journal->description));
$journal->description = '(no description)';
$note->text = trim(sprintf("%s \n%s", $note->text, $object->description));
$object->description = '(no description)';
}
if ('' === $note->text) {
$note->text = (string) $journal->description;
$journal->description = '(no description)';
$note->text = (string) $object->description;
$object->description = '(no description)';
}
$after = $note->text;
event(new TriggeredAuditLog($this->action->rule, $journal, 'update_description', $beforeDescription, $journal->description));
event(new TriggeredAuditLog($this->action->rule, $journal, 'update_notes', $before, $after));
event(new TriggeredAuditLog($this->action->rule, $object, 'update_description', $beforeDescription, $object->description));
event(new TriggeredAuditLog($this->action->rule, $object, 'update_notes', $before, $after));
$note->save();
$journal->save();
$object->save();
return true;
}
}

View File

@@ -51,13 +51,13 @@ class MoveNotesToDescription implements ActionInterface
*/
public function actOnArray(array $journal): bool
{
/** @var TransactionJournal $journal */
$journal = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
if (null === $journal) {
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
if (null === $object) {
Log::error(sprintf('No journal #%d belongs to user #%d.', $journal['transaction_journal_id'], $journal['user_id']));
return false;
}
$note = $journal->notes()->first();
$note = $object->notes()->first();
if (null === $note) {
// nothing to move, return null
return false;
@@ -67,14 +67,14 @@ class MoveNotesToDescription implements ActionInterface
$note->delete();
return false;
}
$before = $journal->description;
$before = $object->description;
$beforeNote = $note->text;
$journal->description = (string) $this->clearString($note->text, false);
$journal->save();
$object->description = (string) $this->clearString($note->text, false);
$object->save();
$note->delete();
event(new TriggeredAuditLog($this->action->rule, $journal, 'update_description', $before, $journal->description));
event(new TriggeredAuditLog($this->action->rule, $journal, 'clear_notes', $beforeNote, null));
event(new TriggeredAuditLog($this->action->rule, $object, 'update_description', $before, $object->description));
event(new TriggeredAuditLog($this->action->rule, $object, 'clear_notes', $beforeNote, null));
return true;
}

View File

@@ -54,11 +54,11 @@ class PrependDescription implements ActionInterface
DB::table('transaction_journals')->where('id', $journal['transaction_journal_id'])->limit(1)->update(['description' => $after]);
// journal
/** @var TransactionJournal $journal */
$journal = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
// audit log
event(new TriggeredAuditLog($this->action->rule, $journal, 'update_description', $before, $after));
event(new TriggeredAuditLog($this->action->rule, $object, 'update_description', $before, $after));
return true;
}

View File

@@ -68,11 +68,11 @@ class PrependNotes implements ActionInterface
$dbNote->save();
// journal
/** @var TransactionJournal $journal */
$journal = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
// audit log
event(new TriggeredAuditLog($this->action->rule, $journal, 'update_notes', $before, $text));
event(new TriggeredAuditLog($this->action->rule, $object, 'update_notes', $before, $text));
return true;
}

View File

@@ -58,11 +58,11 @@ class RemoveAllTags implements ActionInterface
}
Log::debug(sprintf('RuleAction RemoveAllTags removed all tags from journal %d.', $journal['transaction_journal_id']));
/** @var TransactionJournal $journal */
$journal = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
// audit log
event(new TriggeredAuditLog($this->action->rule, $journal, 'clear_all_tags', null, null));
event(new TriggeredAuditLog($this->action->rule, $object, 'clear_all_tags', null, null));
return true;
}

View File

@@ -74,9 +74,9 @@ class RemoveTag implements ActionInterface
->where('tag_id', $tag->id)
->delete();
/** @var TransactionJournal $journal */
$journal = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
event(new TriggeredAuditLog($this->action->rule, $journal, 'clear_tag', $tag->tag, null));
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
event(new TriggeredAuditLog($this->action->rule, $object, 'clear_tag', $tag->tag, null));
return true;
}

View File

@@ -87,9 +87,9 @@ class SetBudget implements ActionInterface
DB::table('budget_transaction_journal')->where('transaction_journal_id', '=', $journal['transaction_journal_id'])->delete();
DB::table('budget_transaction_journal')->insert(['transaction_journal_id' => $journal['transaction_journal_id'], 'budget_id' => $budget->id]);
/** @var TransactionJournal $journal */
$journal = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
event(new TriggeredAuditLog($this->action->rule, $journal, 'set_budget', null, $budget->name));
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
event(new TriggeredAuditLog($this->action->rule, $object, 'set_budget', null, $budget->name));
return true;
}

View File

@@ -85,9 +85,9 @@ class SetCategory implements ActionInterface
DB::table('category_transaction_journal')->where('transaction_journal_id', '=', $journal['transaction_journal_id'])->delete();
DB::table('category_transaction_journal')->insert(['transaction_journal_id' => $journal['transaction_journal_id'], 'category_id' => $category->id]);
/** @var TransactionJournal $journal */
$journal = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
event(new TriggeredAuditLog($this->action->rule, $journal, 'set_category', null, $category->name));
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
event(new TriggeredAuditLog($this->action->rule, $object, 'set_category', null, $category->name));
return true;
}

View File

@@ -69,10 +69,10 @@ class SetNotes implements ActionInterface
)
);
/** @var TransactionJournal $journal */
$journal = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
event(new TriggeredAuditLog($this->action->rule, $journal, 'update_notes', $oldNotes, $this->action->action_value));
event(new TriggeredAuditLog($this->action->rule, $object, 'update_notes', $oldNotes, $this->action->action_value));
return true;
}