mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-24 12:47:00 +00:00
Reformat code.
This commit is contained in:
@@ -36,16 +36,12 @@ class ExpressionController extends Controller
|
||||
* This endpoint is documented at:
|
||||
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/rules/validateExpression
|
||||
*
|
||||
* @param ValidateExpressionRequest $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validateExpression(ValidateExpressionRequest $request): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
"valid" => true,
|
||||
'valid' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,10 +45,7 @@ class ValidateExpressionRequest extends FormRequest
|
||||
/**
|
||||
* Handle a failed validation attempt.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Validation\Validator $validator
|
||||
* @return void
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
protected function failedValidation(Validator $validator): void
|
||||
{
|
||||
@@ -58,7 +55,7 @@ class ValidateExpressionRequest extends FormRequest
|
||||
$validator,
|
||||
response()->json([
|
||||
'valid' => false,
|
||||
'error' => $error
|
||||
'error' => $error,
|
||||
], 200)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,13 @@ class IndexRequest extends FormRequest
|
||||
use ConvertsDataTypes;
|
||||
use GetSortInstructions;
|
||||
|
||||
public function getAccountTypes(): array
|
||||
{
|
||||
$type = (string)$this->get('type', 'default');
|
||||
|
||||
return $this->mapAccountTypes($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all data from the request.
|
||||
*/
|
||||
@@ -50,13 +57,6 @@ class IndexRequest extends FormRequest
|
||||
return $this->getCarbonDate('date');
|
||||
}
|
||||
|
||||
public function getAccountTypes(): array
|
||||
{
|
||||
$type = (string)$this->get('type', 'default');
|
||||
|
||||
return $this->mapAccountTypes($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* The rules that the incoming request must be matched against.
|
||||
*/
|
||||
|
||||
@@ -36,7 +36,7 @@ trait CollectorProperties
|
||||
public const string TEST = 'Test';
|
||||
|
||||
/** @var array<int, string> */
|
||||
public array $sorting;
|
||||
public array $sorting;
|
||||
private ?int $endRow;
|
||||
private bool $expandGroupSearch;
|
||||
private array $fields;
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Auth;
|
||||
|
||||
use Cookie;
|
||||
use FireflyIII\Events\ActuallyLoggedIn;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
|
||||
@@ -122,13 +122,13 @@ class Account extends Model
|
||||
|
||||
protected $casts
|
||||
= [
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'user_id' => 'integer',
|
||||
'deleted_at' => 'datetime',
|
||||
'active' => 'boolean',
|
||||
'encrypted' => 'boolean',
|
||||
];
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'user_id' => 'integer',
|
||||
'deleted_at' => 'datetime',
|
||||
'active' => 'boolean',
|
||||
'encrypted' => 'boolean',
|
||||
];
|
||||
|
||||
protected $fillable = ['user_id', 'user_group_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban'];
|
||||
|
||||
|
||||
@@ -76,6 +76,13 @@ class RuleAction extends Model
|
||||
|
||||
protected $fillable = ['rule_id', 'action_type', 'action_value', 'order', 'active', 'stop_processing'];
|
||||
|
||||
public function getValue(array $journal): string
|
||||
{
|
||||
$expr = new ActionExpression($this->action_value);
|
||||
|
||||
return $expr->evaluate($journal);
|
||||
}
|
||||
|
||||
public function rule(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Rule::class);
|
||||
@@ -94,10 +101,4 @@ class RuleAction extends Model
|
||||
get: static fn ($value) => (int)$value,
|
||||
);
|
||||
}
|
||||
|
||||
public function getValue(array $journal): string
|
||||
{
|
||||
$expr = new ActionExpression($this->action_value);
|
||||
return $expr->evaluate($journal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,6 +208,7 @@ class FireflyServiceProvider extends ServiceProvider
|
||||
static function () {
|
||||
$expressionLanguage = new ExpressionLanguage();
|
||||
$expressionLanguage->registerProvider(new ActionExpressionLanguageProvider());
|
||||
|
||||
return $expressionLanguage;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -25,27 +25,27 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Rules;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use FireflyIII\TransactionRules\Expressions\ActionExpression;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Translation\PotentiallyTranslatedString;
|
||||
|
||||
class IsValidActionExpression implements ValidationRule
|
||||
{
|
||||
/**
|
||||
* Check that the given action expression is syntactically valid.
|
||||
*
|
||||
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
||||
* @param \Closure(string): PotentiallyTranslatedString $fail
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
public function validate(string $attribute, mixed $value, \Closure $fail): void
|
||||
{
|
||||
$value ??= '';
|
||||
$expr = new ActionExpression($value);
|
||||
|
||||
if (!$expr->isValid()) {
|
||||
$fail('validation.rule_action_expression')->translate([
|
||||
'error' => $expr->getValidationError()->getMessage()
|
||||
'error' => $expr->getValidationError()->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,9 +72,9 @@ class OperatorQuerySearch implements SearchInterface
|
||||
private GroupCollectorInterface $collector;
|
||||
private CurrencyRepositoryInterface $currencyRepository;
|
||||
private array $excludeTags;
|
||||
private array $includeAnyTags;
|
||||
private array $includeAnyTags;
|
||||
// added to fix #8632
|
||||
private array $includeTags;
|
||||
private array $includeTags;
|
||||
private array $invalidOperators;
|
||||
private int $limit;
|
||||
private Collection $operators;
|
||||
|
||||
@@ -29,57 +29,57 @@ use Symfony\Component\ExpressionLanguage\SyntaxError;
|
||||
|
||||
class ActionExpression
|
||||
{
|
||||
private static array $NAMES = array(
|
||||
"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"
|
||||
);
|
||||
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',
|
||||
];
|
||||
|
||||
private ExpressionLanguage $expressionLanguage;
|
||||
private string $expr;
|
||||
@@ -89,15 +89,15 @@ class ActionExpression
|
||||
public function __construct(string $expr)
|
||||
{
|
||||
$this->expressionLanguage = app(ExpressionLanguage::class);
|
||||
$this->expr = $expr;
|
||||
$this->expr = $expr;
|
||||
|
||||
$this->isExpression = self::isExpression($expr);
|
||||
$this->validationError = $this->validate();
|
||||
$this->isExpression = self::isExpression($expr);
|
||||
$this->validationError = $this->validate();
|
||||
}
|
||||
|
||||
private static function isExpression(string $expr): bool
|
||||
{
|
||||
return str_starts_with($expr, "=");
|
||||
return str_starts_with($expr, '=');
|
||||
}
|
||||
|
||||
private function validate(): ?SyntaxError
|
||||
@@ -108,6 +108,7 @@ class ActionExpression
|
||||
|
||||
try {
|
||||
$this->lint();
|
||||
|
||||
return null;
|
||||
} catch (SyntaxError $e) {
|
||||
return $e;
|
||||
@@ -130,7 +131,7 @@ class ActionExpression
|
||||
|
||||
public function isValid(): bool
|
||||
{
|
||||
return $this->validationError === null;
|
||||
return null === $this->validationError;
|
||||
}
|
||||
|
||||
public function getValidationError(): ?SyntaxError
|
||||
@@ -141,7 +142,8 @@ class ActionExpression
|
||||
private function evaluateExpression(string $expr, array $journal): string
|
||||
{
|
||||
$result = $this->expressionLanguage->evaluate($expr, $journal);
|
||||
return strval($result);
|
||||
|
||||
return (string) $result;
|
||||
}
|
||||
|
||||
public function evaluate(array $journal): string
|
||||
|
||||
@@ -32,8 +32,8 @@ class ActionExpressionLanguageProvider implements ExpressionFunctionProviderInte
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
ExpressionFunction::fromPhp("substr"),
|
||||
ExpressionFunction::fromPhp("strlen")
|
||||
ExpressionFunction::fromPhp('substr'),
|
||||
ExpressionFunction::fromPhp('strlen'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use FireflyIII\Services\Password\Verifier;
|
||||
use FireflyIII\Support\ParseDateString;
|
||||
use FireflyIII\TransactionRules\Expressions\ActionExpression;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Validation\Validator;
|
||||
use PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException;
|
||||
|
||||
Reference in New Issue
Block a user