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;
}
}