Small code cleanup.

This commit is contained in:
James Cole
2024-03-16 23:06:16 +01:00
parent 1bd3019c16
commit 7224f1be6f
11 changed files with 93 additions and 87 deletions

View File

@@ -29,63 +29,63 @@ use Symfony\Component\ExpressionLanguage\SyntaxError;
class ActionExpression
{
private static array $NAMES = [
// 'transaction_group_id',
// 'user_id',
// 'user_group_id',
'created_at',
'updated_at',
'transaction_group_title',
'group_created_at',
'group_updated_at',
// 'transaction_journal_id',
// 'transaction_type_id',
'description',
'date',
// 'order',
'transaction_type_type',
// 'source_transaction_id',
'source_account_id',
// 'reconciled',
'amount',
// 'currency_id',
'currency_code',
'currency_name',
'currency_symbol',
'currency_decimal_places',
'foreign_amount',
// 'foreign_currency_id',
'foreign_currency_code',
'foreign_currency_name',
'foreign_currency_symbol',
'foreign_currency_decimal_places',
'destination_account_id',
'source_account_name',
'source_account_iban',
'source_account_type',
'destination_account_name',
'destination_account_iban',
'destination_account_type',
'category_id',
'category_name',
'budget_id',
'budget_name',
'tags',
// 'attachments',
'interest_date',
'payment_date',
'invoice_date',
'book_date',
'due_date',
'process_date',
// 'destination_transaction_id',
'notes',
];
private static array $NAMES
= [
// 'transaction_group_id',
// 'user_id',
// 'user_group_id',
'created_at',
'updated_at',
'transaction_group_title',
'group_created_at',
'group_updated_at',
// 'transaction_journal_id',
// 'transaction_type_id',
'description',
'date',
// 'order',
'transaction_type_type',
// 'source_transaction_id',
'source_account_id',
// 'reconciled',
'amount',
// 'currency_id',
'currency_code',
'currency_name',
'currency_symbol',
'currency_decimal_places',
'foreign_amount',
// 'foreign_currency_id',
'foreign_currency_code',
'foreign_currency_name',
'foreign_currency_symbol',
'foreign_currency_decimal_places',
'destination_account_id',
'source_account_name',
'source_account_iban',
'source_account_type',
'destination_account_name',
'destination_account_iban',
'destination_account_type',
'category_id',
'category_name',
'budget_id',
'budget_name',
'tags',
// 'attachments',
'interest_date',
'payment_date',
'invoice_date',
'book_date',
'due_date',
'process_date',
// 'destination_transaction_id',
'notes',
];
private string $expr;
private ExpressionLanguage $expressionLanguage;
private string $expr;
private bool $isExpression;
private ?SyntaxError $validationError;
private bool $isExpression;
private ?SyntaxError $validationError;
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
{
if (!$this->isExpression) {
@@ -130,9 +125,9 @@ class ActionExpression
$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
@@ -140,11 +135,16 @@ class ActionExpression
return $this->validationError;
}
public function isValid(): bool
{
return null === $this->validationError;
}
private function evaluateExpression(string $expr, array $journal): string
{
$result = $this->expressionLanguage->evaluate($expr, $journal);
return (string) $result;
return (string)$result;
}
public function evaluate(array $journal): string