Various PSR12 code cleanup

This commit is contained in:
James Cole
2022-12-29 19:42:26 +01:00
parent dbf3e76ecc
commit 6cfdc58cb1
415 changed files with 7462 additions and 6874 deletions

View File

@@ -58,14 +58,14 @@ class BelongsUser implements Rule
*/
public function message(): string
{
return (string) trans('validation.belongs_user');
return (string)trans('validation.belongs_user');
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
* @throws FireflyException
@@ -77,25 +77,25 @@ 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)),
};
}
/**
* @param string $attribute
* @param string $attribute
*
* @return string
*/
@@ -113,7 +113,7 @@ class BelongsUser implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -127,7 +127,7 @@ class BelongsUser implements Rule
}
/**
* @param string $value
* @param string $value
*
* @return bool
*/
@@ -139,9 +139,9 @@ class BelongsUser implements Rule
}
/**
* @param string $class
* @param string $field
* @param string $value
* @param string $class
* @param string $field
* @param string $value
*
* @return int
*
@@ -160,7 +160,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++;
@@ -172,7 +172,7 @@ class BelongsUser implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -187,7 +187,7 @@ class BelongsUser implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -202,7 +202,7 @@ class BelongsUser implements Rule
}
/**
* @param string $value
* @param string $value
*
* @return bool
*/
@@ -215,7 +215,7 @@ class BelongsUser implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -230,7 +230,7 @@ class BelongsUser implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -242,7 +242,7 @@ class BelongsUser implements Rule
}
/**
* @param string $value
* @param string $value
*
* @return bool
*/
@@ -254,7 +254,7 @@ class BelongsUser implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/

View File

@@ -1,4 +1,5 @@
<?php
/**
* IsAssetAccountId.php
* Copyright (c) 2019 james@firefly-iii.org
@@ -46,14 +47,14 @@ class IsAssetAccountId implements Rule
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*/
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,14 +39,14 @@ class IsBoolean implements Rule
*/
public function message(): string
{
return (string) trans('validation.boolean');
return (string)trans('validation.boolean');
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*/

View File

@@ -43,20 +43,20 @@ class IsDateOrTime implements Rule
*/
public function message()
{
return (string) trans('validation.date_or_time');
return (string)trans('validation.date_or_time');
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*/
public function passes($attribute, $value): bool
{
$value = (string) $value;
$value = (string)$value;
if ('' === $value) {
return false;
}

View File

@@ -41,14 +41,14 @@ class IsTransferAccount implements Rule
*/
public function message(): string
{
return (string) trans('validation.not_transfer_account');
return (string)trans('validation.not_transfer_account');
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*/
@@ -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

@@ -55,7 +55,7 @@ class IsValidAttachmentModel implements Rule
*
* @codeCoverageIgnore
*
* @param string $model
* @param string $model
*/
public function __construct(string $model)
{
@@ -64,7 +64,7 @@ class IsValidAttachmentModel implements Rule
}
/**
* @param string $model
* @param string $model
*
* @return string
*/
@@ -85,14 +85,14 @@ class IsValidAttachmentModel implements Rule
*/
public function message(): string
{
return (string) trans('validation.model_id_invalid');
return (string)trans('validation.model_id_invalid');
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*/
@@ -118,11 +118,11 @@ class IsValidAttachmentModel implements Rule
}
$method = $methods[$this->model];
return $this->$method((int) $value);
return $this->$method((int)$value);
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -136,7 +136,7 @@ class IsValidAttachmentModel implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -150,7 +150,7 @@ class IsValidAttachmentModel implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -164,7 +164,7 @@ class IsValidAttachmentModel implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -178,7 +178,7 @@ class IsValidAttachmentModel implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -191,7 +191,7 @@ class IsValidAttachmentModel implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -205,7 +205,7 @@ class IsValidAttachmentModel implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -219,7 +219,7 @@ class IsValidAttachmentModel implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -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

@@ -37,12 +37,12 @@ class IsValidBulkClause implements Rule
private array $rules;
/**
* @param string $type
* @param string $type
*/
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');
}
/**
@@ -54,14 +54,14 @@ class IsValidBulkClause implements Rule
}
/**
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*/
public function passes($attribute, $value): bool
{
$result = $this->basicValidation((string) $value);
$result = $this->basicValidation((string)$value);
if (false === $result) {
return false;
}
@@ -72,7 +72,7 @@ class IsValidBulkClause implements Rule
/**
* Does basic rule based validation.
*
* @param string $value
* @param string $value
*
* @return bool
*/
@@ -81,24 +81,24 @@ 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;
}
/**
* @var string $arrayKey
* @var mixed $arrayValue
* @var mixed $arrayValue
*/
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,14 +38,14 @@ class LessThanPiggyTarget implements Rule
*/
public function message(): string
{
return (string) trans('validation.current_target_amount');
return (string)trans('validation.current_target_amount');
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*/

View File

@@ -42,8 +42,8 @@ class UniqueAccountNumber implements Rule
*
* @codeCoverageIgnore
*
* @param Account|null $account
* @param string|null $expectedType
* @param Account|null $account
* @param string|null $expectedType
*/
public function __construct(?Account $account, ?string $expectedType)
{
@@ -72,14 +72,14 @@ 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');
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*
@@ -143,19 +143,19 @@ class UniqueAccountNumber implements Rule
}
/**
* @param string $type
* @param string $accountNumber
* @param string $type
* @param string $accountNumber
*
* @return int
*/
private function countHits(string $type, string $accountNumber): int
{
$query = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->where('accounts.user_id', auth()->user()->id)
->where('account_types.type', $type)
->where('account_meta.name', '=', 'account_number')
->where('account_meta.data', json_encode($accountNumber));
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->where('accounts.user_id', auth()->user()->id)
->where('account_types.type', $type)
->where('account_meta.name', '=', 'account_number')
->where('account_meta.data', json_encode($accountNumber));
if (null !== $this->account) {
$query->where('accounts.id', '!=', $this->account->id);

View File

@@ -41,8 +41,8 @@ class UniqueIban implements Rule
*
* @codeCoverageIgnore
*
* @param Account|null $account
* @param string|null $expectedType
* @param Account|null $account
* @param string|null $expectedType
*/
public function __construct(?Account $account, ?string $expectedType)
{
@@ -69,14 +69,14 @@ class UniqueIban implements Rule
*/
public function message(): string
{
return (string) trans('validation.unique_iban_for_user');
return (string)trans('validation.unique_iban_for_user');
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*
@@ -139,8 +139,8 @@ class UniqueIban implements Rule
}
/**
* @param string $type
* @param string $iban
* @param string $type
* @param string $iban
*
* @return int
*/

View File

@@ -42,14 +42,14 @@ class ValidJournals implements Rule
*/
public function message(): string
{
return (string) trans('validation.invalid_selection');
return (string)trans('validation.invalid_selection');
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*

View File

@@ -39,21 +39,21 @@ class ValidRecurrenceRepetitionType implements Rule
*/
public function message(): string
{
return (string) trans('validation.valid_recurrence_rep_type');
return (string)trans('validation.valid_recurrence_rep_type');
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*
*/
public function passes($attribute, $value): bool
{
$value = (string) $value;
$value = (string)$value;
if ('daily' === $value) {
return true;
}

View File

@@ -42,21 +42,21 @@ class ValidRecurrenceRepetitionValue implements Rule
*/
public function message(): string
{
return (string) trans('validation.valid_recurrence_rep_type');
return (string)trans('validation.valid_recurrence_rep_type');
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*
*/
public function passes($attribute, $value): bool
{
$value = (string) $value;
$value = (string)$value;
if ('daily' === $value) {
return true;
@@ -86,19 +86,19 @@ class ValidRecurrenceRepetitionValue implements Rule
}
/**
* @param string $value
* @param string $value
*
* @return bool
*/
private function validateMonthly(string $value): bool
{
$dayOfMonth = (int) substr($value, 8);
$dayOfMonth = (int)substr($value, 8);
return $dayOfMonth > 0 && $dayOfMonth < 32;
}
/**
* @param string $value
* @param string $value
*
* @return bool
*
@@ -109,8 +109,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;
}
@@ -119,19 +119,19 @@ class ValidRecurrenceRepetitionValue implements Rule
}
/**
* @param string $value
* @param string $value
*
* @return bool
*/
private function validateWeekly(string $value): bool
{
$dayOfWeek = (int) substr($value, 7);
$dayOfWeek = (int)substr($value, 7);
return $dayOfWeek > 0 && $dayOfWeek < 8;
}
/**
* @param string $value
* @param string $value
*
* @return bool
*/