Various PSR12 code cleanup

This commit is contained in:
James Cole
2022-12-29 19:42:26 +01:00
parent dbf3e76ecc
commit 6cfdc58cb1
415 changed files with 7462 additions and 6874 deletions

View File

@@ -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
*/

View File

@@ -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)
{

View File

@@ -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)
{

View File

@@ -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;

View File

@@ -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 = '';
}

View File

@@ -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));

View File

@@ -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;

View File

@@ -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']));

View File

@@ -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;

View File

@@ -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

View File

@@ -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
*/

View File

@@ -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

View File

@@ -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)
{

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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();

View File

@@ -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)
{

View File

@@ -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 = '';
}

View File

@@ -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)
{

View File

@@ -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;
}

View File

@@ -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)
{

View File

@@ -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)
{

View File

@@ -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'])

View File

@@ -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
*/

View File

@@ -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)
{

View File

@@ -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
*/

View File

@@ -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;
}