mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 22:21:42 +00:00
Code cleanup
This commit is contained in:
@@ -101,6 +101,50 @@ 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; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
@@ -135,40 +179,6 @@ class BelongsUser implements Rule
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*
|
||||
@@ -209,6 +219,18 @@ class BelongsUser implements Rule
|
||||
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
|
||||
*
|
||||
@@ -226,35 +248,13 @@ class BelongsUser implements Rule
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function validateCategoryId(int $value): bool
|
||||
private function validateAccountId(int $value): bool
|
||||
{
|
||||
$count = Category::where('id', '=', $value)->where('user_id', '=', auth()->user()->id)->count();
|
||||
|
||||
return 1 === $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user