Code cleanup.

This commit is contained in:
James Cole
2023-12-20 19:35:52 +01:00
parent c4f6366642
commit 64ec0cf62e
997 changed files with 12908 additions and 28136 deletions

View File

@@ -46,9 +46,7 @@ class RecurrenceFormRequest extends FormRequest
/**
* Get the data required by the controller.
*
* @return array
* @throws FireflyException
*
*/
public function getAll(): array
{
@@ -94,7 +92,6 @@ class RecurrenceFormRequest extends FormRequest
'weekend' => $this->convertInteger('weekend'),
],
],
];
// fill in foreign currency data
@@ -131,6 +128,7 @@ class RecurrenceFormRequest extends FormRequest
// replace category name with a new category:
$factory = app(CategoryFactory::class);
$factory->setUser(auth()->user());
/**
* @var int $index
* @var array $transaction
@@ -148,45 +146,8 @@ 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.
*
* @return array
*
*/
public function rules(): array
{
@@ -195,7 +156,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',
@@ -239,7 +200,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:
@@ -259,11 +220,11 @@ class RecurrenceFormRequest extends FormRequest
}
// update some rules in case the user is editing a post:
/** @var Recurrence|null $recurrence */
/** @var null|Recurrence $recurrence */
$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';
}
@@ -272,10 +233,6 @@ class RecurrenceFormRequest extends FormRequest
/**
* Configure the validator instance with special rules for after the basic validation rules.
*
* @param Validator $validator
*
* @return void
*/
public function withValidator(Validator $validator): void
{
@@ -290,13 +247,12 @@ class RecurrenceFormRequest extends FormRequest
/**
* Validates the given account information. Switches on given transaction type.
*
* @param Validator $validator
*
* @throws FireflyException
*/
public function validateAccountInformation(Validator $validator): void
{
app('log')->debug('Now in validateAccountInformation (RecurrenceFormRequest)()');
/** @var AccountValidator $accountValidator */
$accountValidator = app(AccountValidator::class);
$data = $validator->getData();
@@ -332,7 +288,7 @@ class RecurrenceFormRequest extends FormRequest
}
// validate source account.
$validSource = $accountValidator->validateSource(['id' => $sourceId,]);
$validSource = $accountValidator->validateSource(['id' => $sourceId]);
// do something with result:
if (false === $validSource) {
@@ -344,7 +300,7 @@ class RecurrenceFormRequest extends FormRequest
}
// validate destination account
$validDestination = $accountValidator->validateDestination(['id' => $destinationId,]);
$validDestination = $accountValidator->validateDestination(['id' => $destinationId]);
// do something with result:
if (false === $validDestination) {
$message = (string)trans('validation.generic_invalid_destination');
@@ -352,4 +308,36 @@ class RecurrenceFormRequest extends FormRequest
$validator->errors()->add('withdrawal_destination_id', $message);
}
}
/**
* Parses repetition data.
*/
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;
}
}