Fix a few small bugs and rearrange code.

This commit is contained in:
James Cole
2024-03-10 11:57:21 +01:00
parent 3413b9b5b5
commit d5ea78025e
10 changed files with 192 additions and 40 deletions

View File

@@ -30,31 +30,31 @@ use Symfony\Component\ExpressionLanguage\SyntaxError;
class ActionExpression
{
private static array $NAMES = [
'transaction_group_id',
'user_id',
'user_group_id',
// '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',
// 'transaction_journal_id',
// 'transaction_type_id',
'description',
'date',
'order',
// 'order',
'transaction_type_type',
'source_transaction_id',
// 'source_transaction_id',
'source_account_id',
'reconciled',
// 'reconciled',
'amount',
'currency_id',
// 'currency_id',
'currency_code',
'currency_name',
'currency_symbol',
'currency_decimal_places',
'foreign_amount',
'foreign_currency_id',
// 'foreign_currency_id',
'foreign_currency_code',
'foreign_currency_name',
'foreign_currency_symbol',
@@ -71,14 +71,14 @@ class ActionExpression
'budget_id',
'budget_name',
'tags',
'attachments',
// 'attachments',
'interest_date',
'payment_date',
'invoice_date',
'book_date',
'due_date',
'process_date',
'destination_transaction_id',
// 'destination_transaction_id',
'notes',
];

View File

@@ -32,24 +32,34 @@ class ActionExpressionLanguageProvider implements ExpressionFunctionProviderInte
public function getFunctions(): array
{
return [
new ExpressionFunction('constant', function ($str): string {
return sprintf('(is_string(%1$s) ? strtolower(%1$s) : %1$s)', $str.'!');
}, function ($arguments, $str): string {
if (!is_string($str)) {
return $str;
}
new ExpressionFunction(
'constant',
function ($str): string {
return sprintf('(is_string(%1$s) ? strtolower(%1$s) : %1$s)', $str.'!');
},
// @SuppressWarnings(PHPMD.UnusedFormalParameter)
function ($arguments, $str): string {
if (!is_string($str)) {
return (string) $str;
}
return strtolower($str.'!');
}),
new ExpressionFunction('enum', function ($str): string {
return sprintf('(is_string(%1$s) ? strtolower(%1$s) : %1$s)', $str.'?');
}, function ($arguments, $str): string {
if (!is_string($str)) {
return $str;
return strtolower($str.'!');
}
),
new ExpressionFunction(
'enum',
function ($str): string {
return sprintf('(is_string(%1$s) ? strtolower(%1$s) : %1$s)', $str.'?');
},
// @SuppressWarnings(PHPMD.UnusedFormalParameter)
function ($arguments, $str): string {
if (!is_string($str)) {
return (string) $str;
}
return strtolower($str).'?';
}),
return strtolower($str).'?';
}
),
ExpressionFunction::fromPhp('substr'),
ExpressionFunction::fromPhp('strlen'),