Code cleanup.

This commit is contained in:
James Cole
2023-12-20 19:35:52 +01:00
parent c4f6366642
commit 64ec0cf62e
997 changed files with 12908 additions and 28136 deletions

View File

@@ -41,20 +41,17 @@ class RemoteUserGuard implements Guard
{
protected Application $application;
protected UserProvider $provider;
protected User | null $user;
protected null|User $user;
/**
* Create a new authentication guard.
*
* @param UserProvider $provider
* @param Application $app
*
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __construct(UserProvider $provider, Application $app)
{
/** @var Request|null $request */
/** @var null|Request $request */
$request = $app->get('request');
app('log')->debug(sprintf('Created RemoteUserGuard for %s "%s"', $request?->getMethod(), $request?->getRequestUri()));
$this->application = $app;
@@ -62,9 +59,6 @@ class RemoteUserGuard implements Guard
$this->user = null;
}
/**
*
*/
public function authenticate(): void
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
@@ -84,6 +78,7 @@ class RemoteUserGuard implements Guard
if (null === $userID || '' === $userID) {
app('log')->error(sprintf('No user in header "%s".', $header));
throw new FireflyException('The guard header was unexpectedly empty. See the logs.');
}
@@ -112,86 +107,72 @@ class RemoteUserGuard implements Guard
$this->user = $retrievedUser;
}
/**
* @inheritDoc
*/
public function guest(): bool
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
return !$this->check();
}
/**
* @inheritDoc
*/
public function check(): bool
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
return null !== $this->user();
}
/**
* @inheritDoc
*/
public function user(): ?User
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
$user = $this->user;
if (null === $user) {
app('log')->debug('User is NULL');
return null;
}
return $user;
}
/**
* @inheritDoc
*/
public function hasUser(): bool
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
throw new FireflyException('Did not implement RemoteUserGuard::hasUser()');
}
/**
* @inheritDoc
* @SuppressWarnings(PHPMD.ShortMethodName)
*/
public function id(): int | string | null
public function id(): null|int|string
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
return $this->user?->id;
}
/**
* @inheritDoc
*/
public function setUser(Authenticatable | User | null $user)
public function setUser(null|Authenticatable|User $user)
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
if ($user instanceof User) {
$this->user = $user;
return;
}
app('log')->error(sprintf('Did not set user at %s', __METHOD__));
}
/**
* @inheritDoc
*/
public function validate(array $credentials = [])
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
throw new FireflyException('Did not implement RemoteUserGuard::validate()');
}
/**
* @return bool
*/
public function viaRemember(): bool
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
return false;
}
}

View File

@@ -30,25 +30,19 @@ use FireflyIII\Models\Role;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Auth\UserProvider;
use Str;
/**
* Class RemoteUserProvider
*/
class RemoteUserProvider implements UserProvider
{
/**
* @inheritDoc
*/
public function retrieveByCredentials(array $credentials)
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
throw new FireflyException(sprintf('Did not implement %s', __METHOD__));
}
/**
* @inheritDoc
*/
public function retrieveById($identifier): User
{
app('log')->debug(sprintf('Now at %s(%s)', __METHOD__, $identifier));
@@ -60,7 +54,7 @@ class RemoteUserProvider implements UserProvider
'blocked' => false,
'blocked_code' => null,
'email' => $identifier,
'password' => bcrypt(Str::random(64)),
'password' => bcrypt(\Str::random(64)),
]
);
// if this is the first user, give them admin as well.
@@ -76,30 +70,24 @@ class RemoteUserProvider implements UserProvider
return $user;
}
/**
* @inheritDoc
*/
public function retrieveByToken($identifier, $token)
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
throw new FireflyException(sprintf('A) Did not implement %s', __METHOD__));
}
/**
* @inheritDoc
*/
public function updateRememberToken(Authenticatable $user, $token)
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
throw new FireflyException(sprintf('B) Did not implement %s', __METHOD__));
}
/**
* @inheritDoc
*/
public function validateCredentials(Authenticatable $user, array $credentials)
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
throw new FireflyException(sprintf('C) Did not implement %s', __METHOD__));
}
}