Fix code quality with rector [skip ci]

This commit is contained in:
James Cole
2025-11-09 09:08:03 +01:00
parent d2610be790
commit 68183a0a0e
209 changed files with 1021 additions and 1248 deletions

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\User;
use Illuminate\Support\Facades\Log;
use Carbon\Carbon;
use Exception;
use FireflyIII\Exceptions\FireflyException;
@@ -97,7 +98,7 @@ class UserRepository implements UserRepositoryInterface
public function deleteInvite(InvitedUser $invite): void
{
app('log')->debug(sprintf('Deleting invite #%d', $invite->id));
Log::debug(sprintf('Deleting invite #%d', $invite->id));
$invite->delete();
}
@@ -106,7 +107,7 @@ class UserRepository implements UserRepositoryInterface
*/
public function destroy(User $user): bool
{
app('log')->debug(sprintf('Calling delete() on user %d', $user->id));
Log::debug(sprintf('Calling delete() on user %d', $user->id));
$user->groupMemberships()->delete();
$user->delete();
@@ -123,7 +124,7 @@ class UserRepository implements UserRepositoryInterface
foreach ($groups as $group) {
$count = $group->groupMemberships()->count();
if (0 === $count) {
app('log')->info(sprintf('Deleted empty group #%d ("%s")', $group->id, $group->title));
Log::info(sprintf('Deleted empty group #%d ("%s")', $group->id, $group->title));
$group->delete();
}
}
@@ -198,33 +199,12 @@ class UserRepository implements UserRepositoryInterface
*/
public function getUserData(User $user): array
{
$return = [];
// two factor:
$return['has_2fa'] = null !== $user->mfa_secret;
$return['is_admin'] = $this->hasRole($user, 'owner');
$return['blocked'] = 1 === (int) $user->blocked;
$return['blocked_code'] = $user->blocked_code;
$return['accounts'] = $user->accounts()->count();
$return['journals'] = $user->transactionJournals()->count();
$return['transactions'] = $user->transactions()->count();
$return['attachments'] = $user->attachments()->count();
$return['attachments_size'] = $user->attachments()->sum('size');
$return['bills'] = $user->bills()->count();
$return['categories'] = $user->categories()->count();
$return['budgets'] = $user->budgets()->count();
$return['budgets_with_limits'] = BudgetLimit::distinct()
return ['has_2fa' => null !== $user->mfa_secret, 'is_admin' => $this->hasRole($user, 'owner'), 'blocked' => 1 === (int) $user->blocked, 'blocked_code' => $user->blocked_code, 'accounts' => $user->accounts()->count(), 'journals' => $user->transactionJournals()->count(), 'transactions' => $user->transactions()->count(), 'attachments' => $user->attachments()->count(), 'attachments_size' => $user->attachments()->sum('size'), 'bills' => $user->bills()->count(), 'categories' => $user->categories()->count(), 'budgets' => $user->budgets()->count(), 'budgets_with_limits' => BudgetLimit::distinct()
->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
->where('amount', '>', 0)
->whereNull('budgets.deleted_at')
->where('budgets.user_id', $user->id)
->count('budget_limits.budget_id')
;
$return['rule_groups'] = $user->ruleGroups()->count();
$return['rules'] = $user->rules()->count();
$return['tags'] = $user->tags()->count();
return $return;
->count('budget_limits.budget_id'), 'rule_groups' => $user->ruleGroups()->count(), 'rules' => $user->rules()->count(), 'tags' => $user->tags()->count()];
}
public function hasRole(Authenticatable|User|null $user, string $role): bool
@@ -327,7 +307,7 @@ class UserRepository implements UserRepositoryInterface
{
$roleObject = Role::where('name', $role)->first();
if (null === $roleObject) {
app('log')->error(sprintf('Could not find role "%s" in attachRole()', $role));
Log::error(sprintf('Could not find role "%s" in attachRole()', $role));
return false;
}
@@ -336,7 +316,7 @@ class UserRepository implements UserRepositoryInterface
$user->roles()->attach($roleObject);
} catch (QueryException $e) {
// don't care
app('log')->error(sprintf('Query exception when giving user a role: %s', $e->getMessage()));
Log::error(sprintf('Query exception when giving user a role: %s', $e->getMessage()));
}
return true;