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

@@ -1,4 +1,5 @@
<?php
/**
* UserRepository.php
* Copyright (c) 2019 james@firefly-iii.org
@@ -45,8 +46,8 @@ class UserRepository implements UserRepositoryInterface
* This updates the users email address and records some things so it can be confirmed or undone later.
* The user is blocked until the change is confirmed.
*
* @param User $user
* @param string $newEmail
* @param User $user
* @param string $newEmail
*
* @return bool
* @throws Exception
@@ -59,7 +60,7 @@ class UserRepository implements UserRepositoryInterface
// save old email as pref
app('preferences')->setForUser($user, 'previous_email_latest', $oldEmail);
app('preferences')->setForUser($user, 'previous_email_' . date('Y-m-d-H-i-s'), $oldEmail);
app('preferences')->setForUser($user, 'previous_email_'.date('Y-m-d-H-i-s'), $oldEmail);
// set undo and confirm token:
app('preferences')->setForUser($user, 'email_change_undo_token', bin2hex(random_bytes(16)));
@@ -75,8 +76,8 @@ class UserRepository implements UserRepositoryInterface
}
/**
* @param User $user
* @param string $password
* @param User $user
* @param string $password
*
* @return bool
*/
@@ -89,9 +90,9 @@ class UserRepository implements UserRepositoryInterface
}
/**
* @param User $user
* @param bool $isBlocked
* @param string $code
* @param User $user
* @param bool $isBlocked
* @param string $code
*
* @return bool
*/
@@ -106,9 +107,9 @@ class UserRepository implements UserRepositoryInterface
}
/**
* @param string $name
* @param string $displayName
* @param string $description
* @param string $name
* @param string $displayName
* @param string $description
*
* @return Role
*/
@@ -118,7 +119,7 @@ class UserRepository implements UserRepositoryInterface
}
/**
* @param User $user
* @param User $user
*
* @return bool
* @throws Exception
@@ -167,7 +168,7 @@ class UserRepository implements UserRepositoryInterface
}
/**
* @param int $userId
* @param int $userId
*
* @return User|null
*/
@@ -177,7 +178,7 @@ class UserRepository implements UserRepositoryInterface
}
/**
* @param string $email
* @param string $email
*
* @return User|null
*/
@@ -197,7 +198,15 @@ class UserRepository implements UserRepositoryInterface
}
/**
* @param User $user
* @inheritDoc
*/
public function getInvitedUsers(): Collection
{
return InvitedUser::with('user')->get();
}
/**
* @param User $user
*
* @return string|null
*/
@@ -215,7 +224,7 @@ class UserRepository implements UserRepositoryInterface
/**
* Return basic user information.
*
* @param User $user
* @param User $user
*
* @return array
*/
@@ -226,7 +235,7 @@ class UserRepository implements UserRepositoryInterface
// two factor:
$return['has_2fa'] = $user->mfa_secret !== null;
$return['is_admin'] = $this->hasRole($user, 'owner');
$return['blocked'] = 1 === (int) $user->blocked;
$return['blocked'] = 1 === (int)$user->blocked;
$return['blocked_code'] = $user->blocked_code;
$return['accounts'] = $user->accounts()->count();
$return['journals'] = $user->transactionJournals()->count();
@@ -250,8 +259,8 @@ class UserRepository implements UserRepositoryInterface
}
/**
* @param User $user
* @param string $role
* @param User $user
* @param string $role
*
* @return bool
*/
@@ -285,11 +294,23 @@ class UserRepository implements UserRepositoryInterface
return $invitee;
}
/**
* @inheritDoc
*/
public function redeemCode(string $code): void
{
$obj = InvitedUser::where('invite_code', $code)->where('redeemed', 0)->first();
if ($obj) {
$obj->redeemed = true;
$obj->save();
}
}
/**
* Set MFA code.
*
* @param User $user
* @param string|null $code
* @param User $user
* @param string|null $code
*/
public function setMFACode(User $user, ?string $code): void
{
@@ -298,7 +319,7 @@ class UserRepository implements UserRepositoryInterface
}
/**
* @param array $data
* @param array $data
*
* @return User
*/
@@ -321,8 +342,8 @@ class UserRepository implements UserRepositoryInterface
}
/**
* @param User $user
* @param string $role
* @param User $user
* @param string $role
*
* @return bool
*/
@@ -346,7 +367,7 @@ class UserRepository implements UserRepositoryInterface
}
/**
* @param User $user
* @param User $user
*/
public function unblockUser(User $user): void
{
@@ -358,8 +379,8 @@ class UserRepository implements UserRepositoryInterface
/**
* Update user info.
*
* @param User $user
* @param array $data
* @param User $user
* @param array $data
*
* @return User
* @throws FireflyException
@@ -387,8 +408,8 @@ class UserRepository implements UserRepositoryInterface
* This updates the users email address. Same as changeEmail just without most logging. This makes sure that the undo/confirm routine can't catch this one.
* The user is NOT blocked.
*
* @param User $user
* @param string $newEmail
* @param User $user
* @param string $newEmail
*
* @return bool
* @throws FireflyException
@@ -403,7 +424,7 @@ class UserRepository implements UserRepositoryInterface
// save old email as pref
app('preferences')->setForUser($user, 'admin_previous_email_latest', $oldEmail);
app('preferences')->setForUser($user, 'admin_previous_email_' . date('Y-m-d-H-i-s'), $oldEmail);
app('preferences')->setForUser($user, 'admin_previous_email_'.date('Y-m-d-H-i-s'), $oldEmail);
$user->email = $newEmail;
$user->save();
@@ -414,8 +435,8 @@ class UserRepository implements UserRepositoryInterface
/**
* Remove any role the user has.
*
* @param User $user
* @param string $role
* @param User $user
* @param string $role
*/
public function removeRole(User $user, string $role): void
{
@@ -427,7 +448,7 @@ class UserRepository implements UserRepositoryInterface
}
/**
* @param string $role
* @param string $role
*
* @return Role|null
*/
@@ -436,14 +457,6 @@ class UserRepository implements UserRepositoryInterface
return Role::where('name', $role)->first();
}
/**
* @inheritDoc
*/
public function getInvitedUsers(): Collection
{
return InvitedUser::with('user')->get();
}
/**
* @inheritDoc
*/
@@ -453,16 +466,4 @@ class UserRepository implements UserRepositoryInterface
$invitee = InvitedUser::where('invite_code', $code)->where('expires', '>', $now->format('Y-m-d H:i:s'))->where('redeemed', 0)->first();
return null !== $invitee;
}
/**
* @inheritDoc
*/
public function redeemCode(string $code): void
{
$obj = InvitedUser::where('invite_code', $code)->where('redeemed', 0)->first();
if ($obj) {
$obj->redeemed = true;
$obj->save();
}
}
}