mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-22 03:56:42 +00:00
chore: reformat code.
This commit is contained in:
@@ -118,12 +118,12 @@ class AccountFormRequest extends FormRequest
|
||||
'virtual_balance' => 'numeric|nullable|max:1000000000',
|
||||
'currency_id' => 'exists:transaction_currencies,id',
|
||||
'account_number' => 'between:1,255|uniqueAccountNumberForUser|nullable',
|
||||
'account_role' => 'in:'.$accountRoles,
|
||||
'account_role' => 'in:' . $accountRoles,
|
||||
'active' => 'boolean',
|
||||
'cc_type' => 'in:'.$ccPaymentTypes,
|
||||
'cc_type' => 'in:' . $ccPaymentTypes,
|
||||
'amount_currency_id_opening_balance' => 'exists:transaction_currencies,id',
|
||||
'amount_currency_id_virtual_balance' => 'exists:transaction_currencies,id',
|
||||
'what' => 'in:'.$types,
|
||||
'what' => 'in:' . $types,
|
||||
'interest_period' => 'in:daily,monthly,yearly',
|
||||
];
|
||||
$rules = Location::requestRules($rules);
|
||||
@@ -133,7 +133,7 @@ class AccountFormRequest extends FormRequest
|
||||
if (null !== $account) {
|
||||
// add rules:
|
||||
$rules['id'] = 'belongsToUser:accounts';
|
||||
$rules['name'] = 'required|max:1024|min:1|uniqueAccountForUser:'.$account->id;
|
||||
$rules['name'] = 'required|max:1024|min:1|uniqueAccountForUser:' . $account->id;
|
||||
$rules['iban'] = ['iban', 'nullable', new UniqueIban($account, $account->accountType->type)];
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ class AccountFormRequest extends FormRequest
|
||||
/**
|
||||
* Configure the validator instance with special rules for after the basic validation rules.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
@@ -75,7 +75,7 @@ class BudgetFormStoreRequest extends FormRequest
|
||||
/**
|
||||
* Configure the validator instance with special rules for after the basic validation rules.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
@@ -69,7 +69,7 @@ class BudgetFormUpdateRequest extends FormRequest
|
||||
$budget = $this->route()->parameter('budget');
|
||||
|
||||
if (null !== $budget) {
|
||||
$nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name,'.$budget->id;
|
||||
$nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name,' . $budget->id;
|
||||
}
|
||||
|
||||
return [
|
||||
@@ -85,7 +85,7 @@ class BudgetFormUpdateRequest extends FormRequest
|
||||
/**
|
||||
* Configure the validator instance with special rules for after the basic validation rules.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
@@ -61,7 +61,7 @@ class CategoryFormRequest extends FormRequest
|
||||
$category = $this->route()->parameter('category');
|
||||
|
||||
if (null !== $category) {
|
||||
$nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name,'.$category->id;
|
||||
$nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name,' . $category->id;
|
||||
}
|
||||
|
||||
// fixed
|
||||
|
@@ -133,7 +133,7 @@ class RecurrenceFormRequest extends FormRequest
|
||||
$factory = app(CategoryFactory::class);
|
||||
$factory->setUser(auth()->user());
|
||||
/**
|
||||
* @var int $index
|
||||
* @var int $index
|
||||
* @var array $transaction
|
||||
*/
|
||||
foreach ($return['transactions'] as $index => $transaction) {
|
||||
@@ -149,6 +149,40 @@ class RecurrenceFormRequest extends FormRequest
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses repetition data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function parseRepetitionData(): array
|
||||
{
|
||||
$value = $this->convertString('repetition_type');
|
||||
$return = [
|
||||
'type' => '',
|
||||
'moment' => '',
|
||||
];
|
||||
|
||||
if ('daily' === $value) {
|
||||
$return['type'] = $value;
|
||||
}
|
||||
//monthly,17
|
||||
//ndom,3,7
|
||||
if (in_array(substr($value, 0, 6), ['yearly', 'weekly'], true)) {
|
||||
$return['type'] = substr($value, 0, 6);
|
||||
$return['moment'] = substr($value, 7);
|
||||
}
|
||||
if (str_starts_with($value, 'monthly')) {
|
||||
$return['type'] = substr($value, 0, 7);
|
||||
$return['moment'] = substr($value, 8);
|
||||
}
|
||||
if (str_starts_with($value, 'ndom')) {
|
||||
$return['type'] = substr($value, 0, 4);
|
||||
$return['moment'] = substr($value, 5);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* The rules for this request.
|
||||
*
|
||||
@@ -162,7 +196,7 @@ class RecurrenceFormRequest extends FormRequest
|
||||
$rules = [
|
||||
// mandatory info for recurrence.
|
||||
'title' => 'required|between:1,255|uniqueObjectForUser:recurrences,title',
|
||||
'first_date' => 'required|date|after:'.$today->format('Y-m-d'),
|
||||
'first_date' => 'required|date|after:' . $today->format('Y-m-d'),
|
||||
'repetition_type' => ['required', new ValidRecurrenceRepetitionValue(), new ValidRecurrenceRepetitionType(), 'between:1,20'],
|
||||
'skip' => 'required|numeric|integer|gte:0|lte:31',
|
||||
|
||||
@@ -206,7 +240,7 @@ class RecurrenceFormRequest extends FormRequest
|
||||
|
||||
// if ends at date X, set another rule.
|
||||
if ('until_date' === $this->convertString('repetition_end')) {
|
||||
$rules['repeat_until'] = 'required|date|after:'.$tomorrow->format('Y-m-d');
|
||||
$rules['repeat_until'] = 'required|date|after:' . $tomorrow->format('Y-m-d');
|
||||
}
|
||||
|
||||
// switch on type to expand rules for source and destination accounts:
|
||||
@@ -230,17 +264,34 @@ class RecurrenceFormRequest extends FormRequest
|
||||
$recurrence = $this->route()->parameter('recurrence');
|
||||
if ($recurrence instanceof Recurrence) {
|
||||
$rules['id'] = 'required|numeric|exists:recurrences,id';
|
||||
$rules['title'] = 'required|between:1,255|uniqueObjectForUser:recurrences,title,'.$recurrence->id;
|
||||
$rules['title'] = 'required|between:1,255|uniqueObjectForUser:recurrences,title,' . $recurrence->id;
|
||||
$rules['first_date'] = 'required|date';
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the validator instance with special rules for after the basic validation rules.
|
||||
*
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function withValidator(Validator $validator): void
|
||||
{
|
||||
$validator->after(
|
||||
function (Validator $validator) {
|
||||
// validate all account info
|
||||
$this->validateAccountInformation($validator);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the given account information. Switches on given transaction type.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
@@ -302,55 +353,4 @@ class RecurrenceFormRequest extends FormRequest
|
||||
$validator->errors()->add('withdrawal_destination_id', $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the validator instance with special rules for after the basic validation rules.
|
||||
*
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function withValidator(Validator $validator): void
|
||||
{
|
||||
$validator->after(
|
||||
function (Validator $validator) {
|
||||
// validate all account info
|
||||
$this->validateAccountInformation($validator);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses repetition data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function parseRepetitionData(): array
|
||||
{
|
||||
$value = $this->convertString('repetition_type');
|
||||
$return = [
|
||||
'type' => '',
|
||||
'moment' => '',
|
||||
];
|
||||
|
||||
if ('daily' === $value) {
|
||||
$return['type'] = $value;
|
||||
}
|
||||
//monthly,17
|
||||
//ndom,3,7
|
||||
if (in_array(substr($value, 0, 6), ['yearly', 'weekly'], true)) {
|
||||
$return['type'] = substr($value, 0, 6);
|
||||
$return['moment'] = substr($value, 7);
|
||||
}
|
||||
if (str_starts_with($value, 'monthly')) {
|
||||
$return['type'] = substr($value, 0, 7);
|
||||
$return['moment'] = substr($value, 8);
|
||||
}
|
||||
if (str_starts_with($value, 'ndom')) {
|
||||
$return['type'] = substr($value, 0, 4);
|
||||
$return['moment'] = substr($value, 5);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
@@ -39,7 +39,53 @@ class RuleFormRequest extends FormRequest
|
||||
use ChecksLogin;
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* Get all data for controller.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function getRuleData(): array
|
||||
{
|
||||
return [
|
||||
'title' => $this->convertString('title'),
|
||||
'rule_group_id' => $this->convertInteger('rule_group_id'),
|
||||
'active' => $this->boolean('active'),
|
||||
'trigger' => $this->convertString('trigger'),
|
||||
'description' => $this->stringWithNewlines('description'),
|
||||
'stop_processing' => $this->boolean('stop_processing'),
|
||||
'strict' => $this->boolean('strict'),
|
||||
'triggers' => $this->getRuleTriggerData(),
|
||||
'actions' => $this->getRuleActionData(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getRuleTriggerData(): array
|
||||
{
|
||||
$return = [];
|
||||
$triggerData = $this->get('triggers');
|
||||
if (is_array($triggerData)) {
|
||||
foreach ($triggerData as $trigger) {
|
||||
$stopProcessing = $trigger['stop_processing'] ?? '0';
|
||||
$prohibited = $trigger['prohibited'] ?? '0';
|
||||
$set = [
|
||||
'type' => $trigger['type'] ?? 'invalid',
|
||||
'value' => $trigger['value'] ?? '',
|
||||
'stop_processing' => 1 === (int)$stopProcessing,
|
||||
'prohibited' => 1 === (int)$prohibited,
|
||||
];
|
||||
$set = self::replaceAmountTrigger($set);
|
||||
$return[] = $set;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @return array
|
||||
*/
|
||||
public static function replaceAmountTrigger(array $array): array
|
||||
@@ -67,24 +113,24 @@ class RuleFormRequest extends FormRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all data for controller.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function getRuleData(): array
|
||||
private function getRuleActionData(): array
|
||||
{
|
||||
return [
|
||||
'title' => $this->convertString('title'),
|
||||
'rule_group_id' => $this->convertInteger('rule_group_id'),
|
||||
'active' => $this->boolean('active'),
|
||||
'trigger' => $this->convertString('trigger'),
|
||||
'description' => $this->stringWithNewlines('description'),
|
||||
'stop_processing' => $this->boolean('stop_processing'),
|
||||
'strict' => $this->boolean('strict'),
|
||||
'triggers' => $this->getRuleTriggerData(),
|
||||
'actions' => $this->getRuleActionData(),
|
||||
];
|
||||
$return = [];
|
||||
$actionData = $this->get('actions');
|
||||
if (is_array($actionData)) {
|
||||
foreach ($actionData as $action) {
|
||||
$stopProcessing = $action['stop_processing'] ?? '0';
|
||||
$return[] = [
|
||||
'type' => $action['type'] ?? 'invalid',
|
||||
'value' => $action['value'] ?? '',
|
||||
'stop_processing' => 1 === (int)$stopProcessing,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,9 +156,9 @@ class RuleFormRequest extends FormRequest
|
||||
'stop_processing' => 'boolean',
|
||||
'rule_group_id' => 'required|belongsToUser:rule_groups',
|
||||
'trigger' => 'required|in:store-journal,update-journal',
|
||||
'triggers.*.type' => 'required|in:'.implode(',', $validTriggers),
|
||||
'triggers.*.type' => 'required|in:' . implode(',', $validTriggers),
|
||||
'triggers.*.value' => sprintf('required_if:triggers.*.type,%s|max:1024|min:1|ruleTriggerValue', $contextTriggers),
|
||||
'actions.*.type' => 'required|in:'.implode(',', $validActions),
|
||||
'actions.*.type' => 'required|in:' . implode(',', $validActions),
|
||||
'actions.*.value' => sprintf('required_if:actions.*.type,%s|min:0|max:1024|ruleActionValue', $contextActions),
|
||||
'strict' => 'in:0,1',
|
||||
];
|
||||
@@ -121,55 +167,9 @@ class RuleFormRequest extends FormRequest
|
||||
$rule = $this->route()->parameter('rule');
|
||||
|
||||
if (null !== $rule) {
|
||||
$rules['title'] = 'required|between:1,100|uniqueObjectForUser:rules,title,'.$rule->id;
|
||||
$rules['title'] = 'required|between:1,100|uniqueObjectForUser:rules,title,' . $rule->id;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getRuleActionData(): array
|
||||
{
|
||||
$return = [];
|
||||
$actionData = $this->get('actions');
|
||||
if (is_array($actionData)) {
|
||||
foreach ($actionData as $action) {
|
||||
$stopProcessing = $action['stop_processing'] ?? '0';
|
||||
$return[] = [
|
||||
'type' => $action['type'] ?? 'invalid',
|
||||
'value' => $action['value'] ?? '',
|
||||
'stop_processing' => 1 === (int)$stopProcessing,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getRuleTriggerData(): array
|
||||
{
|
||||
$return = [];
|
||||
$triggerData = $this->get('triggers');
|
||||
if (is_array($triggerData)) {
|
||||
foreach ($triggerData as $trigger) {
|
||||
$stopProcessing = $trigger['stop_processing'] ?? '0';
|
||||
$prohibited = $trigger['prohibited'] ?? '0';
|
||||
$set = [
|
||||
'type' => $trigger['type'] ?? 'invalid',
|
||||
'value' => $trigger['value'] ?? '',
|
||||
'stop_processing' => 1 === (int)$stopProcessing,
|
||||
'prohibited' => 1 === (int)$prohibited,
|
||||
];
|
||||
$set = self::replaceAmountTrigger($set);
|
||||
$return[] = $set;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
@@ -69,7 +69,7 @@ class RuleGroupFormRequest extends FormRequest
|
||||
$ruleGroup = $this->route()->parameter('ruleGroup');
|
||||
|
||||
if (null !== $ruleGroup) {
|
||||
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title,'.$ruleGroup->id;
|
||||
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title,' . $ruleGroup->id;
|
||||
}
|
||||
|
||||
return [
|
||||
|
@@ -50,8 +50,8 @@ class SelectTransactionsRequest extends FormRequest
|
||||
$today = today(config('app.timezone'))->addDay()->format('Y-m-d');
|
||||
|
||||
return [
|
||||
'start' => 'required|date|after:'.$first,
|
||||
'end' => 'required|date|before:'.$today,
|
||||
'start' => 'required|date|after:' . $first,
|
||||
'end' => 'required|date|before:' . $today,
|
||||
'accounts' => 'required',
|
||||
'accounts.*' => 'required|exists:accounts,id|belongsToUser:accounts',
|
||||
];
|
||||
|
@@ -69,7 +69,7 @@ class TagFormRequest extends FormRequest
|
||||
$tagRule = 'required|max:1024|min:1|uniqueObjectForUser:tags,tag';
|
||||
if (null !== $tag) {
|
||||
$idRule = 'belongsToUser:tags';
|
||||
$tagRule = 'required|max:1024|min:1|uniqueObjectForUser:tags,tag,'.$tag->id;
|
||||
$tagRule = 'required|max:1024|min:1|uniqueObjectForUser:tags,tag,' . $tag->id;
|
||||
}
|
||||
|
||||
$rules = [
|
||||
|
@@ -49,7 +49,7 @@ class TestRuleFormRequest extends FormRequest
|
||||
$validTriggers = $this->getTriggers();
|
||||
|
||||
return [
|
||||
'rule-trigger.*' => 'required|max:1024|min:1|in:'.implode(',', $validTriggers),
|
||||
'rule-trigger.*' => 'required|max:1024|min:1|in:' . implode(',', $validTriggers),
|
||||
'rule-trigger-value.*' => 'required|max:1024|min:1|ruleTriggerValue',
|
||||
];
|
||||
}
|
||||
|
Reference in New Issue
Block a user