PHPStorm can order methods by alphabet, who knew.

This commit is contained in:
James Cole
2024-02-22 20:11:09 +01:00
parent f9d4a43e05
commit 68c9c4ec3c
221 changed files with 5840 additions and 5843 deletions

View File

@@ -46,7 +46,7 @@ class JournalLinkRequest extends FormRequest
$return = [];
$linkType = $this->get('link_type');
$parts = explode('_', $linkType);
$return['link_type_id'] = (int) $parts[0];
$return['link_type_id'] = (int)$parts[0];
$return['transaction_journal_id'] = $this->convertInteger('opposing');
$return['notes'] = $this->convertString('notes');
$return['direction'] = $parts[1];

View File

@@ -150,6 +150,38 @@ class RecurrenceFormRequest extends FormRequest
return $return;
}
/**
* 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;
}
/**
* The rules for this request.
*/
@@ -278,18 +310,18 @@ class RecurrenceFormRequest extends FormRequest
$throwError = true;
if ('withdrawal' === $type) {
$throwError = false;
$sourceId = (int) $data['source_id'];
$destinationId = (int) $data['withdrawal_destination_id'];
$sourceId = (int)$data['source_id'];
$destinationId = (int)$data['withdrawal_destination_id'];
}
if ('deposit' === $type) {
$throwError = false;
$sourceId = (int) $data['deposit_source_id'];
$destinationId = (int) ($data['destination_id'] ?? 0);
$sourceId = (int)$data['deposit_source_id'];
$destinationId = (int)($data['destination_id'] ?? 0);
}
if ('transfer' === $type) {
$throwError = false;
$sourceId = (int) $data['source_id'];
$destinationId = (int) ($data['destination_id'] ?? 0);
$sourceId = (int)$data['source_id'];
$destinationId = (int)($data['destination_id'] ?? 0);
}
if (true === $throwError) {
throw new FireflyException(sprintf('Cannot handle transaction type "%s"', $this->convertString('transaction_type')));
@@ -300,7 +332,7 @@ class RecurrenceFormRequest extends FormRequest
// do something with result:
if (false === $validSource) {
$message = (string) trans('validation.generic_invalid_source');
$message = (string)trans('validation.generic_invalid_source');
$validator->errors()->add('source_id', $message);
$validator->errors()->add('deposit_source_id', $message);
@@ -311,41 +343,9 @@ class RecurrenceFormRequest extends FormRequest
$validDestination = $accountValidator->validateDestination(['id' => $destinationId]);
// do something with result:
if (false === $validDestination) {
$message = (string) trans('validation.generic_invalid_destination');
$message = (string)trans('validation.generic_invalid_destination');
$validator->errors()->add('destination_id', $message);
$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;
}
}

View File

@@ -55,7 +55,7 @@ class ReportFormRequest extends FormRequest
$collection = new Collection();
if (is_array($set)) {
foreach ($set as $accountId) {
$account = $repository->find((int) $accountId);
$account = $repository->find((int)$accountId);
if (null !== $account) {
$collection->push($account);
}
@@ -76,7 +76,7 @@ class ReportFormRequest extends FormRequest
$collection = new Collection();
if (is_array($set)) {
foreach ($set as $budgetId) {
$budget = $repository->find((int) $budgetId);
$budget = $repository->find((int)$budgetId);
if (null !== $budget) {
$collection->push($budget);
}
@@ -97,7 +97,7 @@ class ReportFormRequest extends FormRequest
$collection = new Collection();
if (is_array($set)) {
foreach ($set as $categoryId) {
$category = $repository->find((int) $categoryId);
$category = $repository->find((int)$categoryId);
if (null !== $category) {
$collection->push($category);
}
@@ -118,7 +118,7 @@ class ReportFormRequest extends FormRequest
$collection = new Collection();
if (is_array($set)) {
foreach ($set as $accountId) {
$account = $repository->find((int) $accountId);
$account = $repository->find((int)$accountId);
if (null !== $account) {
$collection->push($account);
}
@@ -137,7 +137,7 @@ class ReportFormRequest extends FormRequest
{
$date = today(config('app.timezone'));
$range = $this->get('daterange');
$parts = explode(' - ', (string) $range);
$parts = explode(' - ', (string)$range);
if (2 === count($parts)) {
$string = $parts[1];
// validate as date
@@ -175,7 +175,7 @@ class ReportFormRequest extends FormRequest
{
$date = today(config('app.timezone'));
$range = $this->get('daterange');
$parts = explode(' - ', (string) $range);
$parts = explode(' - ', (string)$range);
if (2 === count($parts)) {
$string = $parts[0];
// validate as date
@@ -229,7 +229,7 @@ class ReportFormRequest extends FormRequest
continue;
}
$tag = $repository->find((int) $tagTag);
$tag = $repository->find((int)$tagTag);
if (null !== $tag) {
$collection->push($tag);
}

View File

@@ -58,6 +58,28 @@ class RuleFormRequest extends FormRequest
];
}
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;
}
public static function replaceAmountTrigger(array $array): array
{
// do some sneaky search and replace.
@@ -83,6 +105,24 @@ class RuleFormRequest extends FormRequest
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;
}
/**
* Rules for this request.
*/
@@ -127,44 +167,4 @@ class RuleFormRequest extends FormRequest
Log::channel('audit')->error(sprintf('Validation errors in %s', __CLASS__), $validator->errors()->toArray());
}
}
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;
}
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;
}
}