chore: reformat code.

This commit is contained in:
James Cole
2023-06-21 12:34:58 +02:00
parent 8d87abde64
commit 3dcb35710b
799 changed files with 23319 additions and 22173 deletions

View File

@@ -62,8 +62,8 @@ class BelongsUser implements Rule
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
* @throws FireflyException
@@ -93,9 +93,53 @@ class BelongsUser implements Rule
}
/**
* @param string $class
* @param string $field
* @param string $value
* @param string $attribute
*
* @return string
*/
private function parseAttribute(string $attribute): string
{
$parts = explode('.', $attribute);
if (1 === count($parts)) {
return $attribute;
}
if (3 === count($parts)) {
return $parts[2];
}
return $attribute;
}
/**
* @param int $value
*
* @return bool
*/
private function validatePiggyBankId(int $value): bool
{
$count = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')
->where('piggy_banks.id', '=', $value)
->where('accounts.user_id', '=', auth()->user()->id)->count();
return 1 === $count;
}
/**
* @param string $value
*
* @return bool
*/
private function validatePiggyBankName(string $value): bool
{
$count = $this->countField(PiggyBank::class, 'name', $value);
return 1 === $count;
}
/**
* @param string $class
* @param string $field
* @param string $value
*
* @return int
*
@@ -126,41 +170,7 @@ class BelongsUser implements Rule
}
/**
* @param string $attribute
*
* @return string
*/
private function parseAttribute(string $attribute): string
{
$parts = explode('.', $attribute);
if (1 === count($parts)) {
return $attribute;
}
if (3 === count($parts)) {
return $parts[2];
}
return $attribute;
}
/**
* @param int $value
*
* @return bool
*/
private function validateAccountId(int $value): bool
{
if (0 === $value) {
// its ok to submit 0. other checks will fail.
return true;
}
$count = Account::where('id', '=', $value)->where('user_id', '=', auth()->user()->id)->count();
return 1 === $count;
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -175,59 +185,7 @@ class BelongsUser implements Rule
}
/**
* @param string $value
*
* @return bool
*/
private function validateBillName(string $value): bool
{
$count = $this->countField(Bill::class, 'name', $value);
Log::debug(sprintf('Result of countField for bill name "%s" is %d', $value, $count));
return 1 === $count;
}
/**
* @param int $value
*
* @return bool
*/
private function validateBudgetId(int $value): bool
{
if (0 === $value) {
return true;
}
$count = Budget::where('id', '=', $value)->where('user_id', '=', auth()->user()->id)->count();
return 1 === $count;
}
/**
* @param string $value
*
* @return bool
*/
private function validateBudgetName(string $value): bool
{
$count = $this->countField(Budget::class, 'name', $value);
return 1 === $count;
}
/**
* @param int $value
*
* @return bool
*/
private function validateCategoryId(int $value): bool
{
$count = Category::where('id', '=', $value)->where('user_id', '=', auth()->user()->id)->count();
return 1 === $count;
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -242,27 +200,69 @@ class BelongsUser implements Rule
}
/**
* @param int $value
* @param string $value
*
* @return bool
*/
private function validatePiggyBankId(int $value): bool
private function validateBillName(string $value): bool
{
$count = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')
->where('piggy_banks.id', '=', $value)
->where('accounts.user_id', '=', auth()->user()->id)->count();
$count = $this->countField(Bill::class, 'name', $value);
Log::debug(sprintf('Result of countField for bill name "%s" is %d', $value, $count));
return 1 === $count;
}
/**
* @param string $value
* @param int $value
*
* @return bool
*/
private function validatePiggyBankName(string $value): bool
private function validateBudgetId(int $value): bool
{
$count = $this->countField(PiggyBank::class, 'name', $value);
if (0 === $value) {
return true;
}
$count = Budget::where('id', '=', $value)->where('user_id', '=', auth()->user()->id)->count();
return 1 === $count;
}
/**
* @param int $value
*
* @return bool
*/
private function validateCategoryId(int $value): bool
{
$count = Category::where('id', '=', $value)->where('user_id', '=', auth()->user()->id)->count();
return 1 === $count;
}
/**
* @param string $value
*
* @return bool
*/
private function validateBudgetName(string $value): bool
{
$count = $this->countField(Budget::class, 'name', $value);
return 1 === $count;
}
/**
* @param int $value
*
* @return bool
*/
private function validateAccountId(int $value): bool
{
if (0 === $value) {
// its ok to submit 0. other checks will fail.
return true;
}
$count = Account::where('id', '=', $value)->where('user_id', '=', auth()->user()->id)->count();
return 1 === $count;
}

View File

@@ -46,8 +46,8 @@ class IsAssetAccountId implements Rule
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*/

View File

@@ -44,8 +44,8 @@ class IsBoolean implements Rule
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*/

View File

@@ -48,8 +48,8 @@ class IsDateOrTime implements Rule
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*/

View File

@@ -47,8 +47,8 @@ class IsTransferAccount implements Rule
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*/

View File

@@ -54,7 +54,7 @@ class IsValidAttachmentModel implements Rule
* IsValidAttachmentModel constructor.
*
*
* @param string $model
* @param string $model
*/
public function __construct(string $model)
{
@@ -62,6 +62,20 @@ class IsValidAttachmentModel implements Rule
$this->model = $model;
}
/**
* @param string $model
*
* @return string
*/
private function normalizeModel(string $model): string
{
$search = ['FireflyIII\Models\\'];
$replace = '';
$model = str_replace($search, $replace, $model);
return sprintf('FireflyIII\Models\%s', $model);
}
/**
* Get the validation error message.
*
@@ -75,8 +89,8 @@ class IsValidAttachmentModel implements Rule
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*/
@@ -106,21 +120,7 @@ class IsValidAttachmentModel implements Rule
}
/**
* @param string $model
*
* @return string
*/
private function normalizeModel(string $model): string
{
$search = ['FireflyIII\Models\\'];
$replace = '';
$model = str_replace($search, $replace, $model);
return sprintf('FireflyIII\Models\%s', $model);
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -134,7 +134,7 @@ class IsValidAttachmentModel implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -148,7 +148,7 @@ class IsValidAttachmentModel implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -162,7 +162,7 @@ class IsValidAttachmentModel implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -176,7 +176,7 @@ class IsValidAttachmentModel implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -189,7 +189,7 @@ class IsValidAttachmentModel implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -203,7 +203,7 @@ class IsValidAttachmentModel implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/
@@ -217,7 +217,7 @@ class IsValidAttachmentModel implements Rule
}
/**
* @param int $value
* @param int $value
*
* @return bool
*/

View File

@@ -37,7 +37,7 @@ class IsValidBulkClause implements Rule
private array $rules;
/**
* @param string $type
* @param string $type
*/
public function __construct(string $type)
{
@@ -54,8 +54,8 @@ class IsValidBulkClause implements Rule
}
/**
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*/
@@ -72,7 +72,7 @@ class IsValidBulkClause implements Rule
/**
* Does basic rule based validation.
*
* @param string $value
* @param string $value
*
* @return bool
*/
@@ -94,7 +94,7 @@ class IsValidBulkClause implements Rule
}
/**
* @var string $arrayKey
* @var mixed $arrayValue
* @var mixed $arrayValue
*/
foreach ($array[$clause] as $arrayKey => $arrayValue) {
if (!array_key_exists($arrayKey, $this->rules[$clause])) {

View File

@@ -44,8 +44,8 @@ class LessThanPiggyTarget implements Rule
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*/

View File

@@ -41,8 +41,8 @@ class UniqueAccountNumber implements Rule
* Create a new rule instance.
*
*
* @param Account|null $account
* @param string|null $expectedType
* @param Account|null $account
* @param string|null $expectedType
*/
public function __construct(?Account $account, ?string $expectedType)
{
@@ -76,8 +76,8 @@ class UniqueAccountNumber implements Rule
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*
@@ -114,28 +114,6 @@ class UniqueAccountNumber implements Rule
return true;
}
/**
* @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));
if (null !== $this->account) {
$query->where('accounts.id', '!=', $this->account->id);
}
return $query->count();
}
/**
* @return array
*
@@ -161,4 +139,26 @@ class UniqueAccountNumber implements Rule
return $maxCounts;
}
/**
* @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));
if (null !== $this->account) {
$query->where('accounts.id', '!=', $this->account->id);
}
return $query->count();
}
}

View File

@@ -41,8 +41,8 @@ class UniqueIban implements ValidationRule
* Create a new rule instance.
*
*
* @param Account|null $account
* @param string|null $expectedType
* @param Account|null $account
* @param string|null $expectedType
*/
public function __construct(?Account $account, ?string $expectedType)
{
@@ -78,11 +78,21 @@ class UniqueIban implements ValidationRule
return (string)trans('validation.unique_iban_for_user');
}
/**
* @inheritDoc
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (!$this->passes($attribute, $value)) {
$fail((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
*
@@ -118,42 +128,6 @@ class UniqueIban implements ValidationRule
return true;
}
/**
* @inheritDoc
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (!$this->passes($attribute, $value)) {
$fail((string)trans('validation.unique_iban_for_user'));
}
}
/**
* @param string $type
* @param string $iban
*
* @return int
*/
private function countHits(string $type, string $iban): int
{
$typesArray = [$type];
if ('liabilities' === $type) {
$typesArray = [AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE];
}
$query
= auth()->user()
->accounts()
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->where('accounts.iban', $iban)
->whereIn('account_types.type', $typesArray);
if (null !== $this->account) {
$query->where('accounts.id', '!=', $this->account->id);
}
return $query->count();
}
/**
* @return array
*
@@ -180,4 +154,30 @@ class UniqueIban implements ValidationRule
return $maxCounts;
}
/**
* @param string $type
* @param string $iban
*
* @return int
*/
private function countHits(string $type, string $iban): int
{
$typesArray = [$type];
if ('liabilities' === $type) {
$typesArray = [AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE];
}
$query
= auth()->user()
->accounts()
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->where('accounts.iban', $iban)
->whereIn('account_types.type', $typesArray);
if (null !== $this->account) {
$query->where('accounts.id', '!=', $this->account->id);
}
return $query->count();
}
}

View File

@@ -48,8 +48,8 @@ class ValidJournals implements Rule
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*

View File

@@ -45,8 +45,8 @@ class ValidRecurrenceRepetitionType implements Rule
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*

View File

@@ -48,8 +48,8 @@ class ValidRecurrenceRepetitionValue implements Rule
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @param string $attribute
* @param mixed $value
*
* @return bool
*
@@ -86,7 +86,7 @@ class ValidRecurrenceRepetitionValue implements Rule
}
/**
* @param string $value
* @param string $value
*
* @return bool
*/
@@ -98,7 +98,7 @@ class ValidRecurrenceRepetitionValue implements Rule
}
/**
* @param string $value
* @param string $value
*
* @return bool
*
@@ -119,7 +119,7 @@ class ValidRecurrenceRepetitionValue implements Rule
}
/**
* @param string $value
* @param string $value
*
* @return bool
*/
@@ -131,7 +131,7 @@ class ValidRecurrenceRepetitionValue implements Rule
}
/**
* @param string $value
* @param string $value
*
* @return bool
*/