mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Small code cleanup.
This commit is contained in:
parent
1bd3019c16
commit
7224f1be6f
@ -72,7 +72,7 @@ interface AccountRepositoryInterface
|
|||||||
|
|
||||||
public function setUser(User $user): void;
|
public function setUser(User $user): void;
|
||||||
|
|
||||||
public function update(Account $account, array $data): Account;
|
|
||||||
|
|
||||||
public function setUserGroup(UserGroup $userGroup): void;
|
public function setUserGroup(UserGroup $userGroup): void;
|
||||||
|
|
||||||
|
public function update(Account $account, array $data): Account;
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ use FireflyIII\TransactionRules\Traits\RefreshNotesTrait;
|
|||||||
class AppendDescription implements ActionInterface
|
class AppendDescription implements ActionInterface
|
||||||
{
|
{
|
||||||
use RefreshNotesTrait;
|
use RefreshNotesTrait;
|
||||||
|
|
||||||
private RuleAction $action;
|
private RuleAction $action;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,6 +38,7 @@ use FireflyIII\TransactionRules\Traits\RefreshNotesTrait;
|
|||||||
class AppendDescriptionToNotes implements ActionInterface
|
class AppendDescriptionToNotes implements ActionInterface
|
||||||
{
|
{
|
||||||
use RefreshNotesTrait;
|
use RefreshNotesTrait;
|
||||||
|
|
||||||
private RuleAction $action;
|
private RuleAction $action;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,6 +36,7 @@ use FireflyIII\TransactionRules\Traits\RefreshNotesTrait;
|
|||||||
class AppendNotes implements ActionInterface
|
class AppendNotes implements ActionInterface
|
||||||
{
|
{
|
||||||
use RefreshNotesTrait;
|
use RefreshNotesTrait;
|
||||||
|
|
||||||
private RuleAction $action;
|
private RuleAction $action;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,6 +40,7 @@ class AppendNotesToDescription implements ActionInterface
|
|||||||
{
|
{
|
||||||
use ConvertsDataTypes;
|
use ConvertsDataTypes;
|
||||||
use RefreshNotesTrait;
|
use RefreshNotesTrait;
|
||||||
|
|
||||||
private RuleAction $action;
|
private RuleAction $action;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,6 +33,7 @@ use FireflyIII\TransactionRules\Traits\RefreshNotesTrait;
|
|||||||
class SetAmount implements ActionInterface
|
class SetAmount implements ActionInterface
|
||||||
{
|
{
|
||||||
use RefreshNotesTrait;
|
use RefreshNotesTrait;
|
||||||
|
|
||||||
private RuleAction $action;
|
private RuleAction $action;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,6 +106,13 @@ class SetAmount implements ActionInterface
|
|||||||
$this->updateAmount($transaction, $amount);
|
$this->updateAmount($transaction, $amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function updateAmount(Transaction $transaction, string $amount): void
|
||||||
|
{
|
||||||
|
$transaction->amount = $amount;
|
||||||
|
$transaction->save();
|
||||||
|
$transaction->transactionJournal->touch();
|
||||||
|
}
|
||||||
|
|
||||||
private function updateNegative(TransactionJournal $object, string $amount): void
|
private function updateNegative(TransactionJournal $object, string $amount): void
|
||||||
{
|
{
|
||||||
/** @var null|Transaction $transaction */
|
/** @var null|Transaction $transaction */
|
||||||
@ -114,11 +122,4 @@ class SetAmount implements ActionInterface
|
|||||||
}
|
}
|
||||||
$this->updateAmount($transaction, $amount);
|
$this->updateAmount($transaction, $amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function updateAmount(Transaction $transaction, string $amount): void
|
|
||||||
{
|
|
||||||
$transaction->amount = $amount;
|
|
||||||
$transaction->save();
|
|
||||||
$transaction->transactionJournal->touch();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ use FireflyIII\TransactionRules\Traits\RefreshNotesTrait;
|
|||||||
class SetDescription implements ActionInterface
|
class SetDescription implements ActionInterface
|
||||||
{
|
{
|
||||||
use RefreshNotesTrait;
|
use RefreshNotesTrait;
|
||||||
|
|
||||||
private RuleAction $action;
|
private RuleAction $action;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -473,6 +473,18 @@ class SearchRuleEngine implements RuleEngineInterface
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.*']);
|
||||||
|
if (null !== $dbNote) {
|
||||||
|
$transaction['notes'] = $dbNote->text;
|
||||||
|
}
|
||||||
|
Log::debug(sprintf('Notes of journal #%d filled in.', $transaction['transaction_journal_id']));
|
||||||
|
|
||||||
|
return $transaction;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if the rule is fired (the collection is larger than zero).
|
* Return true if the rule is fired (the collection is larger than zero).
|
||||||
*
|
*
|
||||||
@ -542,16 +554,4 @@ 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.*']);
|
|
||||||
if (null !== $dbNote) {
|
|
||||||
$transaction['notes'] = $dbNote->text;
|
|
||||||
}
|
|
||||||
Log::debug(sprintf('Notes of journal #%d filled in.', $transaction['transaction_journal_id']));
|
|
||||||
|
|
||||||
return $transaction;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -29,63 +29,63 @@ use Symfony\Component\ExpressionLanguage\SyntaxError;
|
|||||||
|
|
||||||
class ActionExpression
|
class ActionExpression
|
||||||
{
|
{
|
||||||
private static array $NAMES = [
|
private static array $NAMES
|
||||||
// 'transaction_group_id',
|
= [
|
||||||
// 'user_id',
|
// 'transaction_group_id',
|
||||||
// 'user_group_id',
|
// 'user_id',
|
||||||
'created_at',
|
// 'user_group_id',
|
||||||
'updated_at',
|
'created_at',
|
||||||
'transaction_group_title',
|
'updated_at',
|
||||||
'group_created_at',
|
'transaction_group_title',
|
||||||
'group_updated_at',
|
'group_created_at',
|
||||||
// 'transaction_journal_id',
|
'group_updated_at',
|
||||||
// 'transaction_type_id',
|
// 'transaction_journal_id',
|
||||||
'description',
|
// 'transaction_type_id',
|
||||||
'date',
|
'description',
|
||||||
// 'order',
|
'date',
|
||||||
'transaction_type_type',
|
// 'order',
|
||||||
// 'source_transaction_id',
|
'transaction_type_type',
|
||||||
'source_account_id',
|
// 'source_transaction_id',
|
||||||
// 'reconciled',
|
'source_account_id',
|
||||||
'amount',
|
// 'reconciled',
|
||||||
// 'currency_id',
|
'amount',
|
||||||
'currency_code',
|
// 'currency_id',
|
||||||
'currency_name',
|
'currency_code',
|
||||||
'currency_symbol',
|
'currency_name',
|
||||||
'currency_decimal_places',
|
'currency_symbol',
|
||||||
'foreign_amount',
|
'currency_decimal_places',
|
||||||
// 'foreign_currency_id',
|
'foreign_amount',
|
||||||
'foreign_currency_code',
|
// 'foreign_currency_id',
|
||||||
'foreign_currency_name',
|
'foreign_currency_code',
|
||||||
'foreign_currency_symbol',
|
'foreign_currency_name',
|
||||||
'foreign_currency_decimal_places',
|
'foreign_currency_symbol',
|
||||||
'destination_account_id',
|
'foreign_currency_decimal_places',
|
||||||
'source_account_name',
|
'destination_account_id',
|
||||||
'source_account_iban',
|
'source_account_name',
|
||||||
'source_account_type',
|
'source_account_iban',
|
||||||
'destination_account_name',
|
'source_account_type',
|
||||||
'destination_account_iban',
|
'destination_account_name',
|
||||||
'destination_account_type',
|
'destination_account_iban',
|
||||||
'category_id',
|
'destination_account_type',
|
||||||
'category_name',
|
'category_id',
|
||||||
'budget_id',
|
'category_name',
|
||||||
'budget_name',
|
'budget_id',
|
||||||
'tags',
|
'budget_name',
|
||||||
// 'attachments',
|
'tags',
|
||||||
'interest_date',
|
// 'attachments',
|
||||||
'payment_date',
|
'interest_date',
|
||||||
'invoice_date',
|
'payment_date',
|
||||||
'book_date',
|
'invoice_date',
|
||||||
'due_date',
|
'book_date',
|
||||||
'process_date',
|
'due_date',
|
||||||
// 'destination_transaction_id',
|
'process_date',
|
||||||
'notes',
|
// 'destination_transaction_id',
|
||||||
];
|
'notes',
|
||||||
|
];
|
||||||
|
private string $expr;
|
||||||
private ExpressionLanguage $expressionLanguage;
|
private ExpressionLanguage $expressionLanguage;
|
||||||
private string $expr;
|
private bool $isExpression;
|
||||||
private bool $isExpression;
|
private ?SyntaxError $validationError;
|
||||||
private ?SyntaxError $validationError;
|
|
||||||
|
|
||||||
public function __construct(string $expr)
|
public function __construct(string $expr)
|
||||||
{
|
{
|
||||||
@ -116,11 +116,6 @@ class ActionExpression
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function lintExpression(string $expr): void
|
|
||||||
{
|
|
||||||
$this->expressionLanguage->lint($expr, self::$NAMES);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function lint(): void
|
private function lint(): void
|
||||||
{
|
{
|
||||||
if (!$this->isExpression) {
|
if (!$this->isExpression) {
|
||||||
@ -130,9 +125,9 @@ class ActionExpression
|
|||||||
$this->lintExpression(substr($this->expr, 1));
|
$this->lintExpression(substr($this->expr, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isValid(): bool
|
private function lintExpression(string $expr): void
|
||||||
{
|
{
|
||||||
return null === $this->validationError;
|
$this->expressionLanguage->lint($expr, self::$NAMES);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getValidationError(): ?SyntaxError
|
public function getValidationError(): ?SyntaxError
|
||||||
@ -140,11 +135,16 @@ class ActionExpression
|
|||||||
return $this->validationError;
|
return $this->validationError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isValid(): bool
|
||||||
|
{
|
||||||
|
return null === $this->validationError;
|
||||||
|
}
|
||||||
|
|
||||||
private function evaluateExpression(string $expr, array $journal): string
|
private function evaluateExpression(string $expr, array $journal): string
|
||||||
{
|
{
|
||||||
$result = $this->expressionLanguage->evaluate($expr, $journal);
|
$result = $this->expressionLanguage->evaluate($expr, $journal);
|
||||||
|
|
||||||
return (string) $result;
|
return (string)$result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function evaluate(array $journal): string
|
public function evaluate(array $journal): string
|
||||||
|
@ -36,7 +36,7 @@ class ActionExpressionLanguageProvider implements ExpressionFunctionProviderInte
|
|||||||
{
|
{
|
||||||
$function = function ($arguments, $str): string {
|
$function = function ($arguments, $str): string {
|
||||||
if (!is_string($str)) {
|
if (!is_string($str)) {
|
||||||
return (string) $str;
|
return (string)$str;
|
||||||
}
|
}
|
||||||
|
|
||||||
return strtolower($str.'!');
|
return strtolower($str.'!');
|
||||||
|
@ -41,12 +41,12 @@ use Illuminate\Support\Facades\DB;
|
|||||||
class AccountTransformer extends AbstractTransformer
|
class AccountTransformer extends AbstractTransformer
|
||||||
{
|
{
|
||||||
private array $accountMeta;
|
private array $accountMeta;
|
||||||
private array $lastActivity;
|
|
||||||
private array $accountTypes;
|
private array $accountTypes;
|
||||||
private array $balances;
|
private array $balances;
|
||||||
private array $convertedBalances;
|
private array $convertedBalances;
|
||||||
private array $currencies;
|
private array $currencies;
|
||||||
private TransactionCurrency $default;
|
private TransactionCurrency $default;
|
||||||
|
private array $lastActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
|
Loading…
Reference in New Issue
Block a user