Reformat various code.

This commit is contained in:
James Cole
2022-03-29 14:59:58 +02:00
parent 29bed2547c
commit d1a09ff33b
115 changed files with 2700 additions and 2699 deletions

View File

@@ -58,7 +58,7 @@ class BelongsUser implements Rule
*/
public function message(): string
{
return (string)trans('validation.belongs_user');
return (string) trans('validation.belongs_user');
}
/**
@@ -77,19 +77,19 @@ class BelongsUser implements Rule
if (!auth()->check()) {
return true;
}
$attribute = (string)$attribute;
$attribute = (string) $attribute;
Log::debug(sprintf('Going to validate %s', $attribute));
return match ($attribute) {
'piggy_bank_id' => $this->validatePiggyBankId((int)$value),
'piggy_bank_id' => $this->validatePiggyBankId((int) $value),
'piggy_bank_name' => $this->validatePiggyBankName($value),
'bill_id' => $this->validateBillId((int)$value),
'transaction_journal_id' => $this->validateJournalId((int)$value),
'bill_id' => $this->validateBillId((int) $value),
'transaction_journal_id' => $this->validateJournalId((int) $value),
'bill_name' => $this->validateBillName($value),
'budget_id' => $this->validateBudgetId((int)$value),
'category_id' => $this->validateCategoryId((int)$value),
'budget_id' => $this->validateBudgetId((int) $value),
'category_id' => $this->validateCategoryId((int) $value),
'budget_name' => $this->validateBudgetName($value),
'source_id', 'destination_id' => $this->validateAccountId((int)$value),
'source_id', 'destination_id' => $this->validateAccountId((int) $value),
default => throw new FireflyException(sprintf('Rule BelongUser cannot handle "%s"', $attribute)),
};
}
@@ -161,7 +161,7 @@ class BelongsUser implements Rule
}
$count = 0;
foreach ($objects as $object) {
$objectValue = trim((string)$object->$field);
$objectValue = trim((string) $object->$field);
Log::debug(sprintf('Comparing object "%s" with value "%s"', $objectValue, $value));
if ($objectValue === $value) {
$count++;

View File

@@ -53,7 +53,7 @@ class IsAssetAccountId implements Rule
*/
public function passes($attribute, $value): bool
{
$accountId = (int)$value;
$accountId = (int) $value;
$account = Account::with('accountType')->find($accountId);
if (null === $account) {
return false;

View File

@@ -39,7 +39,7 @@ class IsBoolean implements Rule
*/
public function message(): string
{
return (string)trans('validation.boolean');
return (string) trans('validation.boolean');
}
/**

View File

@@ -44,7 +44,7 @@ class IsDateOrTime implements Rule
*/
public function message()
{
return (string)trans('validation.date_or_time');
return (string) trans('validation.date_or_time');
}
/**
@@ -57,7 +57,7 @@ class IsDateOrTime implements Rule
*/
public function passes($attribute, $value): bool
{
$value = (string)$value;
$value = (string) $value;
if ('' === $value) {
return false;
}

View File

@@ -41,7 +41,7 @@ class IsTransferAccount implements Rule
*/
public function message(): string
{
return (string)trans('validation.not_transfer_account');
return (string) trans('validation.not_transfer_account');
}
/**
@@ -60,15 +60,15 @@ class IsTransferAccount implements Rule
$validator->setTransactionType(TransactionType::TRANSFER);
$validator->setUser(auth()->user());
$validAccount = $validator->validateSource(['name' => (string)$value,]);
$validAccount = $validator->validateSource(['name' => (string) $value,]);
if (true === $validAccount) {
Log::debug('Found account based on name. Return true.');
// found by name, use repos to return.
return true;
}
$validAccount = $validator->validateSource(['id' => (int)$value,]);
Log::debug(sprintf('Search by id (%d), result is %s.', (int)$value, var_export($validAccount, true)));
$validAccount = $validator->validateSource(['id' => (int) $value,]);
Log::debug(sprintf('Search by id (%d), result is %s.', (int) $value, var_export($validAccount, true)));
return false !== $validAccount;
}

View File

@@ -85,7 +85,7 @@ class IsValidAttachmentModel implements Rule
*/
public function message(): string
{
return (string)trans('validation.model_id_invalid');
return (string) trans('validation.model_id_invalid');
}
/**
@@ -118,7 +118,7 @@ class IsValidAttachmentModel implements Rule
}
$method = $methods[$this->model];
return $this->$method((int)$value);
return $this->$method((int) $value);
}
/**
@@ -229,6 +229,6 @@ class IsValidAttachmentModel implements Rule
$repository = app(JournalAPIRepositoryInterface::class);
$repository->setUser(auth()->user());
return null !== $repository->findTransaction((int)$value);
return null !== $repository->findTransaction((int) $value);
}
}

View File

@@ -42,7 +42,7 @@ class IsValidBulkClause implements Rule
public function __construct(string $type)
{
$this->rules = config(sprintf('bulk.%s', $type));
$this->error = (string)trans('firefly.belongs_user');
$this->error = (string) trans('firefly.belongs_user');
}
/**
@@ -61,7 +61,7 @@ class IsValidBulkClause implements Rule
*/
public function passes($attribute, $value): bool
{
$result = $this->basicValidation((string)$value);
$result = $this->basicValidation((string) $value);
if (false === $result) {
return false;
}
@@ -81,14 +81,14 @@ class IsValidBulkClause implements Rule
try {
$array = json_decode($value, true, 8, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
$this->error = (string)trans('validation.json');
$this->error = (string) trans('validation.json');
return false;
}
$clauses = ['where', 'update'];
foreach ($clauses as $clause) {
if (!array_key_exists($clause, $array)) {
$this->error = (string)trans(sprintf('validation.missing_%s', $clause));
$this->error = (string) trans(sprintf('validation.missing_%s', $clause));
return false;
}
@@ -98,7 +98,7 @@ class IsValidBulkClause implements Rule
*/
foreach ($array[$clause] as $arrayKey => $arrayValue) {
if (!array_key_exists($arrayKey, $this->rules[$clause])) {
$this->error = (string)trans(sprintf('validation.invalid_%s_key', $clause));
$this->error = (string) trans(sprintf('validation.invalid_%s_key', $clause));
return false;
}

View File

@@ -38,7 +38,7 @@ class LessThanPiggyTarget implements Rule
*/
public function message(): string
{
return (string)trans('validation.current_target_amount');
return (string) trans('validation.current_target_amount');
}
/**

View File

@@ -72,7 +72,7 @@ class UniqueAccountNumber implements Rule
*/
public function message(): string
{
return (string)trans('validation.unique_account_number_for_user');
return (string) trans('validation.unique_account_number_for_user');
}
/**

View File

@@ -69,7 +69,7 @@ class UniqueIban implements Rule
*/
public function message(): string
{
return (string)trans('validation.unique_iban_for_user');
return (string) trans('validation.unique_iban_for_user');
}
/**

View File

@@ -42,7 +42,7 @@ class ValidJournals implements Rule
*/
public function message(): string
{
return (string)trans('validation.invalid_selection');
return (string) trans('validation.invalid_selection');
}
/**

View File

@@ -40,7 +40,7 @@ class ValidRecurrenceRepetitionType implements Rule
*/
public function message(): string
{
return (string)trans('validation.valid_recurrence_rep_type');
return (string) trans('validation.valid_recurrence_rep_type');
}
/**
@@ -54,7 +54,7 @@ class ValidRecurrenceRepetitionType implements Rule
*/
public function passes($attribute, $value): bool
{
$value = (string)$value;
$value = (string) $value;
if ('daily' === $value) {
return true;
}

View File

@@ -43,7 +43,7 @@ class ValidRecurrenceRepetitionValue implements Rule
*/
public function message(): string
{
return (string)trans('validation.valid_recurrence_rep_type');
return (string) trans('validation.valid_recurrence_rep_type');
}
/**
@@ -57,7 +57,7 @@ class ValidRecurrenceRepetitionValue implements Rule
*/
public function passes($attribute, $value): bool
{
$value = (string)$value;
$value = (string) $value;
if ('daily' === $value) {
return true;
@@ -93,7 +93,7 @@ class ValidRecurrenceRepetitionValue implements Rule
*/
private function validateMonthly(string $value): bool
{
$dayOfMonth = (int)substr($value, 8);
$dayOfMonth = (int) substr($value, 8);
return $dayOfMonth > 0 && $dayOfMonth < 32;
}
@@ -110,8 +110,8 @@ class ValidRecurrenceRepetitionValue implements Rule
if (2 !== count($parameters)) {
return false;
}
$nthDay = (int)($parameters[0] ?? 0.0);
$dayOfWeek = (int)($parameters[1] ?? 0.0);
$nthDay = (int) ($parameters[0] ?? 0.0);
$dayOfWeek = (int) ($parameters[1] ?? 0.0);
if ($nthDay < 1 || $nthDay > 5) {
return false;
}
@@ -126,7 +126,7 @@ class ValidRecurrenceRepetitionValue implements Rule
*/
private function validateWeekly(string $value): bool
{
$dayOfWeek = (int)substr($value, 7);
$dayOfWeek = (int) substr($value, 7);
return $dayOfWeek > 0 && $dayOfWeek < 8;
}