mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Various PSR12 code cleanup
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* ActionInterface.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -31,7 +32,7 @@ interface ActionInterface
|
||||
* Execute the action on an array. Returns "true" if the action was a success and the action
|
||||
* was applied. Returns false if otherwise.
|
||||
*
|
||||
* @param array $journal
|
||||
* @param array $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* AddTag.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -40,7 +41,7 @@ class AddTag implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* AppendDescription.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -37,7 +38,7 @@ class AppendDescription implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
|
@@ -37,7 +37,7 @@ class AppendDescriptionToNotes implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
@@ -66,7 +66,7 @@ class AppendDescriptionToNotes implements ActionInterface
|
||||
$note->text = trim(sprintf("%s \n%s", $note->text, $object->description));
|
||||
}
|
||||
if ('' === $note->text) {
|
||||
$note->text = (string) $object->description;
|
||||
$note->text = (string)$object->description;
|
||||
}
|
||||
$after = $note->text;
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* AppendNotes.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -38,7 +39,7 @@ class AppendNotes implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
@@ -50,12 +51,12 @@ class AppendNotes implements ActionInterface
|
||||
*/
|
||||
public function actOnArray(array $journal): bool
|
||||
{
|
||||
$dbNote = Note::where('noteable_id', (int) $journal['transaction_journal_id'])
|
||||
->where('noteable_type', TransactionJournal::class)
|
||||
->first(['notes.*']);
|
||||
$dbNote = Note::where('noteable_id', (int)$journal['transaction_journal_id'])
|
||||
->where('noteable_type', TransactionJournal::class)
|
||||
->first(['notes.*']);
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note();
|
||||
$dbNote->noteable_id = (int) $journal['transaction_journal_id'];
|
||||
$dbNote->noteable_id = (int)$journal['transaction_journal_id'];
|
||||
$dbNote->noteable_type = TransactionJournal::class;
|
||||
$dbNote->text = '';
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@ class AppendNotesToDescription implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
@@ -71,8 +71,8 @@ class AppendNotesToDescription implements ActionInterface
|
||||
}
|
||||
// only append if there is something to append
|
||||
if ('' !== $note->text) {
|
||||
$before = $object->description;
|
||||
$object->description = trim(sprintf("%s %s", $object->description, (string) $this->clearString($note->text, false)));
|
||||
$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));
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* ClearBudget.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -38,7 +39,7 @@ class ClearBudget implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
@@ -52,7 +53,7 @@ class ClearBudget implements ActionInterface
|
||||
{
|
||||
/** @var TransactionJournal $object */
|
||||
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
|
||||
$budget = $object->budgets()->first();
|
||||
$budget = $object->budgets()->first();
|
||||
if (null === $budget) {
|
||||
Log::debug(sprintf('RuleAction ClearBudget, no budget in journal #%d.', $journal['transaction_journal_id']));
|
||||
return false;
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* ClearCategory.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -38,7 +39,7 @@ class ClearCategory implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
@@ -51,7 +52,7 @@ class ClearCategory implements ActionInterface
|
||||
public function actOnArray(array $journal): bool
|
||||
{
|
||||
/** @var TransactionJournal $object */
|
||||
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
|
||||
$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']));
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* ClearNotes.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -38,7 +39,7 @@ class ClearNotes implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
@@ -51,7 +52,7 @@ class ClearNotes implements ActionInterface
|
||||
public function actOnArray(array $journal): bool
|
||||
{
|
||||
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
|
||||
$notes = $object->notes()->first();
|
||||
$notes = $object->notes()->first();
|
||||
if (null === $notes) {
|
||||
Log::debug(sprintf('RuleAction ClearNotes, journal #%d has no notes.', $journal['transaction_journal_id']));
|
||||
return false;
|
||||
|
@@ -45,7 +45,7 @@ class ConvertToDeposit implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
@@ -94,7 +94,7 @@ class ConvertToDeposit implements ActionInterface
|
||||
* Input is a withdrawal from A to B
|
||||
* Is converted to a deposit from C to A.
|
||||
*
|
||||
* @param array $journal
|
||||
* @param array $journal
|
||||
*
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
@@ -142,7 +142,7 @@ class ConvertToDeposit implements ActionInterface
|
||||
* Input is a transfer from A to B.
|
||||
* Output is a deposit from C to B.
|
||||
*
|
||||
* @param array $journal
|
||||
* @param array $journal
|
||||
*
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
|
@@ -45,7 +45,7 @@ class ConvertToTransfer implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
@@ -114,8 +114,8 @@ class ConvertToTransfer implements ActionInterface
|
||||
* A withdrawal is from Asset to Expense.
|
||||
* We replace the Expense with another asset.
|
||||
*
|
||||
* @param array $journal
|
||||
* @param Account $asset
|
||||
* @param array $journal
|
||||
* @param Account $asset
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -154,8 +154,8 @@ class ConvertToTransfer implements ActionInterface
|
||||
* A deposit is from Revenue to Asset.
|
||||
* We replace the Revenue with another asset.
|
||||
*
|
||||
* @param array $journal
|
||||
* @param Account $asset
|
||||
* @param array $journal
|
||||
* @param Account $asset
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
@@ -45,7 +45,7 @@ class ConvertToWithdrawal implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
@@ -127,7 +127,7 @@ class ConvertToWithdrawal implements ActionInterface
|
||||
* Input is a transfer from A to B.
|
||||
* Output is a withdrawal from A to C.
|
||||
*
|
||||
* @param array $journal
|
||||
* @param array $journal
|
||||
*
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* DeleteTransaction.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -40,7 +41,7 @@ class DeleteTransaction implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* LinkToBill.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -43,7 +44,7 @@ class LinkToBill implements ActionInterface
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
@@ -59,14 +60,20 @@ class LinkToBill implements ActionInterface
|
||||
/** @var BillRepositoryInterface $repository */
|
||||
$repository = app(BillRepositoryInterface::class);
|
||||
$repository->setUser($user);
|
||||
$billName = (string) $this->action->action_value;
|
||||
$billName = (string)$this->action->action_value;
|
||||
$bill = $repository->findByName($billName);
|
||||
|
||||
if (null !== $bill && $journal['transaction_type_type'] === TransactionType::WITHDRAWAL) {
|
||||
$count = DB::table('transaction_journals')->where('id', '=', $journal['transaction_journal_id'])
|
||||
->where('bill_id', $bill->id)->count();
|
||||
if (0 !== $count) {
|
||||
Log::error(sprintf('RuleAction LinkToBill could not set the bill of journal #%d to bill "%s": already set.', $journal['transaction_journal_id'], $billName));
|
||||
Log::error(
|
||||
sprintf(
|
||||
'RuleAction LinkToBill could not set the bill of journal #%d to bill "%s": already set.',
|
||||
$journal['transaction_journal_id'],
|
||||
$billName
|
||||
)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -42,7 +42,7 @@ class MoveDescriptionToNotes implements ActionInterface
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
@@ -69,11 +69,11 @@ class MoveDescriptionToNotes implements ActionInterface
|
||||
$before = $note->text;
|
||||
$beforeDescription = $object->description;
|
||||
if ('' !== $note->text) {
|
||||
$note->text = trim(sprintf("%s \n%s", $note->text, $object->description));
|
||||
$note->text = trim(sprintf("%s \n%s", $note->text, $object->description));
|
||||
$object->description = '(no description)';
|
||||
}
|
||||
if ('' === $note->text) {
|
||||
$note->text = (string) $object->description;
|
||||
$note->text = (string)$object->description;
|
||||
$object->description = '(no description)';
|
||||
}
|
||||
$after = $note->text;
|
||||
|
@@ -41,7 +41,7 @@ class MoveNotesToDescription implements ActionInterface
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
@@ -69,9 +69,9 @@ class MoveNotesToDescription implements ActionInterface
|
||||
$note->delete();
|
||||
return false;
|
||||
}
|
||||
$before = $object->description;
|
||||
$beforeNote = $note->text;
|
||||
$object->description = (string) $this->clearString($note->text, false);
|
||||
$before = $object->description;
|
||||
$beforeNote = $note->text;
|
||||
$object->description = (string)$this->clearString($note->text, false);
|
||||
$object->save();
|
||||
$note->delete();
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PrependDescription.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -37,7 +38,7 @@ class PrependDescription implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PrependNotes.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -38,7 +39,7 @@ class PrependNotes implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
@@ -50,12 +51,12 @@ class PrependNotes implements ActionInterface
|
||||
*/
|
||||
public function actOnArray(array $journal): bool
|
||||
{
|
||||
$dbNote = Note::where('noteable_id', (int) $journal['transaction_journal_id'])
|
||||
->where('noteable_type', TransactionJournal::class)
|
||||
->first(['notes.*']);
|
||||
$dbNote = Note::where('noteable_id', (int)$journal['transaction_journal_id'])
|
||||
->where('noteable_type', TransactionJournal::class)
|
||||
->first(['notes.*']);
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note();
|
||||
$dbNote->noteable_id = (int) $journal['transaction_journal_id'];
|
||||
$dbNote->noteable_id = (int)$journal['transaction_journal_id'];
|
||||
$dbNote->noteable_type = TransactionJournal::class;
|
||||
$dbNote->text = '';
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* RemoveAllTags.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -38,7 +39,7 @@ class RemoveAllTags implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* RemoveTag.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -39,7 +40,7 @@ class RemoveTag implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
@@ -64,7 +65,9 @@ class RemoveTag implements ActionInterface
|
||||
}
|
||||
$count = DB::table('tag_transaction_journal')->where('transaction_journal_id', $journal['transaction_journal_id'])->where('tag_id', $tag->id)->count();
|
||||
if (0 === $count) {
|
||||
Log::debug(sprintf('RuleAction RemoveTag tried to remove tag "%s" from journal #%d but no such tag is linked.', $name, $journal['transaction_journal_id']));
|
||||
Log::debug(
|
||||
sprintf('RuleAction RemoveTag tried to remove tag "%s" from journal #%d but no such tag is linked.', $name, $journal['transaction_journal_id'])
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SetBudget.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -40,7 +41,7 @@ class SetBudget implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SetCategory.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -40,7 +41,7 @@ class SetCategory implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SetDescription.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -38,7 +39,7 @@ class SetDescription implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
@@ -52,7 +53,7 @@ class SetDescription implements ActionInterface
|
||||
{
|
||||
/** @var TransactionJournal $object */
|
||||
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
|
||||
$before = $object->description;
|
||||
$before = $object->description;
|
||||
|
||||
DB::table('transaction_journals')
|
||||
->where('id', '=', $journal['transaction_journal_id'])
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SetDestinationAccount.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -44,7 +45,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
@@ -59,7 +60,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
$user = User::find($journal['user_id']);
|
||||
$type = $journal['transaction_type_type'];
|
||||
/** @var TransactionJournal|null $object */
|
||||
$object = $user->transactionJournals()->find((int) $journal['transaction_journal_id']);
|
||||
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
|
||||
if (null === $object) {
|
||||
@@ -98,7 +99,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
|
||||
return false;
|
||||
}
|
||||
if (null !== $newAccount && (int) $newAccount->id === (int) $source->account_id) {
|
||||
if (null !== $newAccount && (int)$newAccount->id === (int)$source->account_id) {
|
||||
Log::error(
|
||||
sprintf(
|
||||
'New destination account ID #%d and current source account ID #%d are the same. Do nothing.',
|
||||
@@ -132,7 +133,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $type
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SetNotes.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -38,7 +39,7 @@ class SetNotes implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SetSourceAccount.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -44,7 +45,7 @@ class SetSourceAccount implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
@@ -59,7 +60,7 @@ class SetSourceAccount implements ActionInterface
|
||||
$user = User::find($journal['user_id']);
|
||||
$type = $journal['transaction_type_type'];
|
||||
/** @var TransactionJournal|null $object */
|
||||
$object = $user->transactionJournals()->find((int) $journal['transaction_journal_id']);
|
||||
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
if (null === $object) {
|
||||
Log::error('Could not find journal.');
|
||||
@@ -93,7 +94,7 @@ class SetSourceAccount implements ActionInterface
|
||||
|
||||
return false;
|
||||
}
|
||||
if (null !== $newAccount && (int) $newAccount->id === (int) $destination->account_id) {
|
||||
if (null !== $newAccount && (int)$newAccount->id === (int)$destination->account_id) {
|
||||
Log::error(
|
||||
sprintf(
|
||||
'New source account ID #%d and current destination account ID #%d are the same. Do nothing.',
|
||||
@@ -127,7 +128,7 @@ class SetSourceAccount implements ActionInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $type
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
|
@@ -91,7 +91,20 @@ class UpdatePiggybank implements ActionInterface
|
||||
Log::debug('Piggy bank account is linked to source, so remove amount from piggy bank.');
|
||||
$this->removeAmount($piggyBank, $journalObj, $destination->amount);
|
||||
|
||||
event(new TriggeredAuditLog($this->action->rule, $journalObj, 'remove_from_piggy', null, ['currency_symbol' => $journalObj->transactionCurrency->symbol, 'decimal_places' => $journalObj->transactionCurrency->decimal_places, 'amount' => $destination->amount, 'piggy' => $piggyBank->name]));
|
||||
event(
|
||||
new TriggeredAuditLog(
|
||||
$this->action->rule,
|
||||
$journalObj,
|
||||
'remove_from_piggy',
|
||||
null,
|
||||
[
|
||||
'currency_symbol' => $journalObj->transactionCurrency->symbol,
|
||||
'decimal_places' => $journalObj->transactionCurrency->decimal_places,
|
||||
'amount' => $destination->amount,
|
||||
'piggy' => $piggyBank->name,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -99,7 +112,20 @@ class UpdatePiggybank implements ActionInterface
|
||||
Log::debug('Piggy bank account is linked to source, so add amount to piggy bank.');
|
||||
$this->addAmount($piggyBank, $journalObj, $destination->amount);
|
||||
|
||||
event(new TriggeredAuditLog($this->action->rule, $journalObj, 'add_to_piggy', null, ['currency_symbol' => $journalObj->transactionCurrency->symbol, 'decimal_places' => $journalObj->transactionCurrency->decimal_places, 'amount' => $destination->amount, 'piggy' => $piggyBank->name]));
|
||||
event(
|
||||
new TriggeredAuditLog(
|
||||
$this->action->rule,
|
||||
$journalObj,
|
||||
'add_to_piggy',
|
||||
null,
|
||||
[
|
||||
'currency_symbol' => $journalObj->transactionCurrency->symbol,
|
||||
'decimal_places' => $journalObj->transactionCurrency->decimal_places,
|
||||
'amount' => $destination->amount,
|
||||
'piggy' => $piggyBank->name,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ interface RuleEngineInterface
|
||||
/**
|
||||
* Add operators added to each search by the rule engine.
|
||||
*
|
||||
* @param array $operator
|
||||
* @param array $operator
|
||||
*/
|
||||
public function addOperator(array $operator): void;
|
||||
|
||||
@@ -58,19 +58,19 @@ interface RuleEngineInterface
|
||||
/**
|
||||
* Add entire rule groups for the engine to execute.
|
||||
*
|
||||
* @param Collection $ruleGroups
|
||||
* @param Collection $ruleGroups
|
||||
*/
|
||||
public function setRuleGroups(Collection $ruleGroups): void;
|
||||
|
||||
/**
|
||||
* Add rules for the engine to execute.
|
||||
*
|
||||
* @param Collection $rules
|
||||
* @param Collection $rules
|
||||
*/
|
||||
public function setRules(Collection $rules): void;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void;
|
||||
}
|
||||
|
@@ -89,7 +89,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
/**
|
||||
* Finds the transactions a strict rule will execute on.
|
||||
*
|
||||
* @param Rule $rule
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -152,7 +152,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
* one search operator for "journal_id" it means the date ranges
|
||||
* in the search may need to be updated.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -178,7 +178,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
@@ -188,7 +188,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
$journalId = 0;
|
||||
foreach ($array as $triggerName => $values) {
|
||||
if ('journal_id' === $triggerName && is_array($values) && 1 === count($values)) {
|
||||
$journalId = (int) trim(($values[0] ?? '"0"'), '"'); // follows format "123".
|
||||
$journalId = (int)trim(($values[0] ?? '"0"'), '"'); // follows format "123".
|
||||
Log::debug(sprintf('Found journal ID #%d', $journalId));
|
||||
}
|
||||
}
|
||||
@@ -209,7 +209,16 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->operators = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -320,7 +329,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
/**
|
||||
* Returns true if the rule has been triggered.
|
||||
*
|
||||
* @param Rule $rule
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
@@ -346,7 +355,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
/**
|
||||
* Return true if the rule is fired (the collection is larger than zero).
|
||||
*
|
||||
* @param Rule $rule
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
@@ -371,8 +380,8 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param Collection $collection
|
||||
* @param Rule $rule
|
||||
* @param Collection $collection
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
@@ -386,8 +395,8 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param array $group
|
||||
* @param Rule $rule
|
||||
* @param array $group
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
@@ -401,8 +410,8 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param array $transaction
|
||||
* @param Rule $rule
|
||||
* @param array $transaction
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
@@ -423,8 +432,8 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleAction $ruleAction
|
||||
* @param array $transaction
|
||||
* @param RuleAction $ruleAction
|
||||
* @param array $transaction
|
||||
*
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
@@ -463,7 +472,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
/**
|
||||
* Return true if the rule is fired (the collection is larger than zero).
|
||||
*
|
||||
* @param Rule $rule
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
@@ -480,7 +489,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleGroup $group
|
||||
* @param RuleGroup $group
|
||||
*
|
||||
* @return void
|
||||
* @throws FireflyException
|
||||
@@ -541,13 +550,4 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->operators = [];
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* ActionFactory.php
|
||||
* Copyright (c) 2019 Robert Horlings
|
||||
@@ -44,7 +45,7 @@ class ActionFactory
|
||||
* with value "Groceries" this method will return a corresponding SetCategory object preset
|
||||
* to "Groceries". Any transaction journal then fed to this object will have its category changed.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param RuleAction $action
|
||||
*
|
||||
* @return ActionInterface
|
||||
*
|
||||
@@ -63,7 +64,7 @@ class ActionFactory
|
||||
* that will match the given action type (ie. "change_category") to the matching class name
|
||||
* (SetCategory) using the configuration (firefly.php).
|
||||
*
|
||||
* @param string $actionType
|
||||
* @param string $actionType
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
@@ -74,12 +75,12 @@ class ActionFactory
|
||||
$actionTypes = self::getActionTypes();
|
||||
|
||||
if (!array_key_exists($actionType, $actionTypes)) {
|
||||
throw new FireflyException('No such action exists ("' . e($actionType) . '").');
|
||||
throw new FireflyException('No such action exists ("'.e($actionType).'").');
|
||||
}
|
||||
|
||||
$class = $actionTypes[$actionType];
|
||||
if (!class_exists($class)) {
|
||||
throw new FireflyException('Could not instantiate class for rule action type "' . e($actionType) . '" (' . e($class) . ').');
|
||||
throw new FireflyException('Could not instantiate class for rule action type "'.e($actionType).'" ('.e($class).').');
|
||||
}
|
||||
|
||||
return $class;
|
||||
|
Reference in New Issue
Block a user