mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-10 13:21:21 +00:00
Code cleanup
This commit is contained in:
@@ -57,7 +57,7 @@ class AppendDescriptionToNotes implements ActionInterface
|
||||
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
|
||||
if (null === $object) {
|
||||
app('log')->error(sprintf('No journal #%d belongs to user #%d.', $journal['transaction_journal_id'], $journal['user_id']));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, (string)trans('rules.journal_other_user')));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, (string) trans('rules.journal_other_user')));
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -72,7 +72,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;
|
||||
|
||||
|
||||
@@ -50,13 +50,13 @@ class AppendNotes implements ActionInterface
|
||||
public function actOnArray(array $journal): bool
|
||||
{
|
||||
$this->refreshNotes($journal);
|
||||
$dbNote = Note::where('noteable_id', (int)$journal['transaction_journal_id'])
|
||||
$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 = '';
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ 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)));
|
||||
$object->description = trim(sprintf('%s %s', $object->description, (string) $this->clearString($note->text)));
|
||||
$object->save();
|
||||
app('log')->debug(sprintf('Journal description is updated to "%s".', $object->description));
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ class ConvertToTransfer implements ActionInterface
|
||||
return '';
|
||||
}
|
||||
|
||||
return (string)$journal->transactions()->where('amount', '<', 0)->first()?->account?->accountType?->type;
|
||||
return (string) $journal->transactions()->where('amount', '<', 0)->first()?->account?->accountType?->type;
|
||||
}
|
||||
|
||||
private function getDestinationType(int $journalId): string
|
||||
@@ -182,7 +182,7 @@ class ConvertToTransfer implements ActionInterface
|
||||
return '';
|
||||
}
|
||||
|
||||
return (string)$journal->transactions()->where('amount', '>', 0)->first()?->account?->accountType?->type;
|
||||
return (string) $journal->transactions()->where('amount', '>', 0)->first()?->account?->accountType?->type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -71,7 +71,7 @@ class MoveDescriptionToNotes implements ActionInterface
|
||||
$object->description = '(no description)';
|
||||
}
|
||||
if ('' === $note->text) {
|
||||
$note->text = (string)$object->description;
|
||||
$note->text = (string) $object->description;
|
||||
$object->description = '(no description)';
|
||||
}
|
||||
$after = $note->text;
|
||||
|
||||
@@ -78,7 +78,7 @@ class MoveNotesToDescription implements ActionInterface
|
||||
}
|
||||
$before = $object->description;
|
||||
$beforeNote = $note->text;
|
||||
$object->description = (string)$this->clearString($note->text);
|
||||
$object->description = (string) $this->clearString($note->text);
|
||||
$object->save();
|
||||
$note->delete();
|
||||
|
||||
|
||||
@@ -46,13 +46,13 @@ class PrependNotes implements ActionInterface
|
||||
|
||||
public function actOnArray(array $journal): bool
|
||||
{
|
||||
$dbNote = Note::where('noteable_id', (int)$journal['transaction_journal_id'])
|
||||
$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 = '';
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ class SetBudget implements ActionInterface
|
||||
$object = $user->transactionJournals()->find($journal['transaction_journal_id']);
|
||||
$oldBudget = $object->budgets()->first();
|
||||
$oldBudgetName = $oldBudget?->name;
|
||||
if ((int)$oldBudget?->id === $budget->id) {
|
||||
if ((int) $oldBudget?->id === $budget->id) {
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.already_linked_to_budget', ['name' => $budget->name])));
|
||||
|
||||
return false;
|
||||
|
||||
@@ -88,7 +88,7 @@ class SetCategory implements ActionInterface
|
||||
$object = $user->transactionJournals()->find($journal['transaction_journal_id']);
|
||||
$oldCategory = $object->categories()->first();
|
||||
$oldCategoryName = $oldCategory?->name;
|
||||
if ((int)$oldCategory?->id === $category->id) {
|
||||
if ((int) $oldCategory?->id === $category->id) {
|
||||
// event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.already_linked_to_category', ['name' => $category->name])));
|
||||
|
||||
return false;
|
||||
|
||||
@@ -57,7 +57,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
$user = User::find($journal['user_id']);
|
||||
|
||||
/** @var null|TransactionJournal $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) {
|
||||
|
||||
@@ -54,7 +54,7 @@ class SetDestinationToCashAccount implements ActionInterface
|
||||
$user = User::find($journal['user_id']);
|
||||
|
||||
/** @var null|TransactionJournal $object */
|
||||
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
|
||||
$object = $user->transactionJournals()->find((int) $journal['transaction_journal_id']);
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
|
||||
if (null === $object) {
|
||||
|
||||
@@ -57,7 +57,7 @@ class SetSourceAccount implements ActionInterface
|
||||
$user = User::find($journal['user_id']);
|
||||
|
||||
/** @var null|TransactionJournal $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) {
|
||||
app('log')->error('Could not find journal.');
|
||||
|
||||
@@ -54,7 +54,7 @@ class SetSourceToCashAccount implements ActionInterface
|
||||
$user = User::find($journal['user_id']);
|
||||
|
||||
/** @var null|TransactionJournal $object */
|
||||
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
|
||||
$object = $user->transactionJournals()->find((int) $journal['transaction_journal_id']);
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
|
||||
if (null === $object) {
|
||||
|
||||
@@ -114,11 +114,11 @@ class UpdatePiggybank implements ActionInterface
|
||||
'add_to_piggy',
|
||||
null,
|
||||
[
|
||||
'currency_symbol' => $journalObj->transactionCurrency->symbol,
|
||||
'decimal_places' => $journalObj->transactionCurrency->decimal_places,
|
||||
'amount' => $destination->amount,
|
||||
'piggy' => $piggyBank->name,
|
||||
'piggy_id' => $piggyBank->id,
|
||||
'currency_symbol' => $journalObj->transactionCurrency->symbol,
|
||||
'decimal_places' => $journalObj->transactionCurrency->decimal_places,
|
||||
'amount' => $destination->amount,
|
||||
'piggy' => $piggyBank->name,
|
||||
'piggy_id' => $piggyBank->id,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
@@ -114,7 +114,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
}
|
||||
|
||||
// if the trigger needs no context, value is different:
|
||||
$needsContext = (bool)(config(sprintf('search.operators.%s.needs_context', $contextSearch)) ?? true);
|
||||
$needsContext = (bool) (config(sprintf('search.operators.%s.needs_context', $contextSearch)) ?? true);
|
||||
if (false === $needsContext) {
|
||||
app('log')->debug(sprintf('SearchRuleEngine:: add a rule trigger (no context): %s:true', $ruleTrigger->trigger_type));
|
||||
$searchArray[$ruleTrigger->trigger_type][] = 'true';
|
||||
@@ -187,7 +187,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".
|
||||
app('log')->debug(sprintf('Found journal ID #%d', $journalId));
|
||||
}
|
||||
}
|
||||
@@ -476,7 +476,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
private function addNotes(array $transaction): array
|
||||
{
|
||||
$transaction['notes'] = '';
|
||||
$dbNote = Note::where('noteable_id', (int)$transaction['transaction_journal_id'])->where('noteable_type', TransactionJournal::class)->first(['notes.*']);
|
||||
$dbNote = Note::where('noteable_id', (int) $transaction['transaction_journal_id'])->where('noteable_type', TransactionJournal::class)->first(['notes.*']);
|
||||
if (null !== $dbNote) {
|
||||
$transaction['notes'] = $dbNote->text;
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ class ActionExpression
|
||||
{
|
||||
$result = $this->expressionLanguage->evaluate($expr, $journal);
|
||||
|
||||
return (string)$result;
|
||||
return (string) $result;
|
||||
}
|
||||
|
||||
public function evaluate(array $journal): string
|
||||
|
||||
@@ -36,7 +36,7 @@ class ActionExpressionLanguageProvider implements ExpressionFunctionProviderInte
|
||||
{
|
||||
$function = function ($arguments, $str): string {
|
||||
if (!is_string($str)) {
|
||||
return (string)$str;
|
||||
return (string) $str;
|
||||
}
|
||||
|
||||
return strtolower($str.'!');
|
||||
|
||||
@@ -33,7 +33,7 @@ trait RefreshNotesTrait
|
||||
final protected function refreshNotes(array $transaction): array
|
||||
{
|
||||
$transaction['notes'] = '';
|
||||
$dbNote = Note::where('noteable_id', (int)$transaction['transaction_journal_id'])->where('noteable_type', TransactionJournal::class)->first(['notes.*']);
|
||||
$dbNote = Note::where('noteable_id', (int) $transaction['transaction_journal_id'])->where('noteable_type', TransactionJournal::class)->first(['notes.*']);
|
||||
if (null !== $dbNote) {
|
||||
$transaction['notes'] = $dbNote->text;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user