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

@@ -65,32 +65,6 @@ class BelongsUser implements ValidationRule
}
}
protected function countField(string $class, string $field, string $value): int
{
$value = trim($value);
$objects = [];
// get all objects belonging to user:
if (PiggyBank::class === $class) {
$objects = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')
->where('accounts.user_id', '=', auth()->user()->id)->get(['piggy_banks.*'])
;
}
if (PiggyBank::class !== $class) {
$objects = $class::where('user_id', '=', auth()->user()->id)->get();
}
$count = 0;
foreach ($objects as $object) {
$objectValue = trim((string)$object->{$field}); // @phpstan-ignore-line
app('log')->debug(sprintf('Comparing object "%s" with value "%s"', $objectValue, $value));
if ($objectValue === $value) {
++$count;
app('log')->debug(sprintf('Hit! Count is now %d', $count));
}
}
return $count;
}
private function parseAttribute(string $attribute): string
{
$parts = explode('.', $attribute);
@@ -121,6 +95,32 @@ class BelongsUser implements ValidationRule
return 1 === $count;
}
protected function countField(string $class, string $field, string $value): int
{
$value = trim($value);
$objects = [];
// get all objects belonging to user:
if (PiggyBank::class === $class) {
$objects = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')
->where('accounts.user_id', '=', auth()->user()->id)->get(['piggy_banks.*'])
;
}
if (PiggyBank::class !== $class) {
$objects = $class::where('user_id', '=', auth()->user()->id)->get();
}
$count = 0;
foreach ($objects as $object) {
$objectValue = trim((string)$object->{$field}); // @phpstan-ignore-line
app('log')->debug(sprintf('Comparing object "%s" with value "%s"', $objectValue, $value));
if ($objectValue === $value) {
++$count;
app('log')->debug(sprintf('Hit! Count is now %d', $count));
}
}
return $count;
}
private function validateBillId(int $value): bool
{
if (0 === $value) {

View File

@@ -78,32 +78,6 @@ class BelongsUserGroup implements ValidationRule
}
}
protected function countField(string $class, string $field, string $value): int
{
$value = trim($value);
$objects = [];
// get all objects belonging to user:
if (PiggyBank::class === $class) {
$objects = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')
->where('accounts.user_group_id', '=', $this->userGroup->id)->get(['piggy_banks.*'])
;
}
if (PiggyBank::class !== $class) {
$objects = $class::where('user_group_id', '=', $this->userGroup->id)->get();
}
$count = 0;
foreach ($objects as $object) {
$objectValue = trim((string)$object->{$field}); // @phpstan-ignore-line
app('log')->debug(sprintf('Comparing object "%s" with value "%s"', $objectValue, $value));
if ($objectValue === $value) {
++$count;
app('log')->debug(sprintf('Hit! Count is now %d', $count));
}
}
return $count;
}
private function parseAttribute(string $attribute): string
{
$parts = explode('.', $attribute);
@@ -134,6 +108,32 @@ class BelongsUserGroup implements ValidationRule
return 1 === $count;
}
protected function countField(string $class, string $field, string $value): int
{
$value = trim($value);
$objects = [];
// get all objects belonging to user:
if (PiggyBank::class === $class) {
$objects = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')
->where('accounts.user_group_id', '=', $this->userGroup->id)->get(['piggy_banks.*'])
;
}
if (PiggyBank::class !== $class) {
$objects = $class::where('user_group_id', '=', $this->userGroup->id)->get();
}
$count = 0;
foreach ($objects as $object) {
$objectValue = trim((string)$object->{$field}); // @phpstan-ignore-line
app('log')->debug(sprintf('Comparing object "%s" with value "%s"', $objectValue, $value));
if ($objectValue === $value) {
++$count;
app('log')->debug(sprintf('Hit! Count is now %d', $count));
}
}
return $count;
}
private function validateBillId(int $value): bool
{
if (0 === $value) {

View File

@@ -57,6 +57,15 @@ class IsValidAttachmentModel implements ValidationRule
$this->model = $model;
}
private function normalizeModel(string $model): string
{
$search = ['FireflyIII\Models\\'];
$replace = '';
$model = str_replace($search, $replace, $model);
return sprintf('FireflyIII\Models\%s', $model);
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
@@ -84,15 +93,6 @@ class IsValidAttachmentModel implements ValidationRule
}
}
private function normalizeModel(string $model): string
{
$search = ['FireflyIII\Models\\'];
$replace = '';
$model = str_replace($search, $replace, $model);
return sprintf('FireflyIII\Models\%s', $model);
}
private function validateAccount(int $value): bool
{
/** @var AccountRepositoryInterface $repository */

View File

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

View File

@@ -146,10 +146,10 @@ class UniqueIban implements ValidationRule
}
$query
= auth()->user()
->accounts()
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->where('accounts.iban', $iban)
->whereIn('account_types.type', $typesArray)
->accounts()
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->where('accounts.iban', $iban)
->whereIn('account_types.type', $typesArray)
;
if (null !== $this->account) {