From de266f5275adcae18edfdedfdd94edc43edf7d15 Mon Sep 17 00:00:00 2001 From: mscherer Date: Sun, 20 Apr 2025 16:59:26 +0200 Subject: [PATCH] Minor cleanup. --- src/Authenticator/CookieAuthenticator.php | 2 +- src/Authenticator/EnvironmentAuthenticator.php | 4 ++-- src/Authenticator/FormAuthenticator.php | 2 +- src/Authenticator/HttpDigestAuthenticator.php | 8 ++++---- src/Authenticator/JwtAuthenticator.php | 2 +- src/Authenticator/SessionAuthenticator.php | 4 ++-- src/Authenticator/TokenAuthenticator.php | 10 +++++----- src/UrlChecker/DefaultUrlChecker.php | 3 +-- src/View/Helper/IdentityHelper.php | 2 +- 9 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/Authenticator/CookieAuthenticator.php b/src/Authenticator/CookieAuthenticator.php index bf52518b..bc6a4ef3 100644 --- a/src/Authenticator/CookieAuthenticator.php +++ b/src/Authenticator/CookieAuthenticator.php @@ -84,7 +84,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface $identity = $this->_identifier->identify(compact('username')); - if (empty($identity)) { + if (!$identity) { return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identifier->getErrors()); } diff --git a/src/Authenticator/EnvironmentAuthenticator.php b/src/Authenticator/EnvironmentAuthenticator.php index ceafd958..f5c04068 100644 --- a/src/Authenticator/EnvironmentAuthenticator.php +++ b/src/Authenticator/EnvironmentAuthenticator.php @@ -137,7 +137,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface return $this->_buildLoginUrlErrorResult($request); } $data = $this->_getData($request); - if (empty($data)) { + if (!$data) { return new Result(null, Result::FAILURE_CREDENTIALS_MISSING, [ 'Environment credentials not found', ]); @@ -147,7 +147,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface $user = $this->_identifier->identify($data); - if (empty($user)) { + if (!$user) { return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identifier->getErrors()); } diff --git a/src/Authenticator/FormAuthenticator.php b/src/Authenticator/FormAuthenticator.php index eb970cee..53a41fd5 100644 --- a/src/Authenticator/FormAuthenticator.php +++ b/src/Authenticator/FormAuthenticator.php @@ -130,7 +130,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface $user = $this->_identifier->identify($data); - if (empty($user)) { + if (!$user) { return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identifier->getErrors()); } diff --git a/src/Authenticator/HttpDigestAuthenticator.php b/src/Authenticator/HttpDigestAuthenticator.php index c5e053e3..e18cdfc7 100644 --- a/src/Authenticator/HttpDigestAuthenticator.php +++ b/src/Authenticator/HttpDigestAuthenticator.php @@ -98,7 +98,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface AbstractIdentifier::CREDENTIAL_USERNAME => $digest['username'], ]); - if (empty($user)) { + if (!$user) { return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND); } @@ -132,13 +132,13 @@ protected function _getDigest(ServerRequestInterface $request): ?array { $server = $request->getServerParams(); $digest = empty($server['PHP_AUTH_DIGEST']) ? null : $server['PHP_AUTH_DIGEST']; - if (empty($digest) && function_exists('apache_request_headers')) { + if (!$digest && function_exists('apache_request_headers')) { $headers = apache_request_headers(); if (!empty($headers['Authorization']) && substr($headers['Authorization'], 0, 7) === 'Digest ') { $digest = substr($headers['Authorization'], 7); } } - if (empty($digest)) { + if (!$digest) { return null; } @@ -165,7 +165,7 @@ public function parseAuthData(string $digest): ?array unset($req[$i[1]]); } - if (empty($req)) { + if (!$req) { return $keys; } diff --git a/src/Authenticator/JwtAuthenticator.php b/src/Authenticator/JwtAuthenticator.php index 06be6164..2afa82fe 100644 --- a/src/Authenticator/JwtAuthenticator.php +++ b/src/Authenticator/JwtAuthenticator.php @@ -110,7 +110,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface $subjectKey => $result[$subjectKey], ]); - if (empty($user)) { + if (!$user) { return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identifier->getErrors()); } diff --git a/src/Authenticator/SessionAuthenticator.php b/src/Authenticator/SessionAuthenticator.php index 8b11f728..a6c98dea 100644 --- a/src/Authenticator/SessionAuthenticator.php +++ b/src/Authenticator/SessionAuthenticator.php @@ -60,7 +60,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface $session = $request->getAttribute('session'); $user = $session->read($sessionKey); - if (empty($user)) { + if (!$user) { return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND); } @@ -71,7 +71,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface } $user = $this->_identifier->identify($credentials); - if (empty($user)) { + if (!$user) { return new Result(null, Result::FAILURE_CREDENTIALS_INVALID); } } diff --git a/src/Authenticator/TokenAuthenticator.php b/src/Authenticator/TokenAuthenticator.php index 89292c53..6ef6075b 100644 --- a/src/Authenticator/TokenAuthenticator.php +++ b/src/Authenticator/TokenAuthenticator.php @@ -75,9 +75,9 @@ protected function stripTokenPrefix(string $token, string $prefix): string */ protected function getTokenFromHeader(ServerRequestInterface $request, ?string $headerLine): ?string { - if (!empty($headerLine)) { + if ($headerLine) { $header = $request->getHeaderLine($headerLine); - if (!empty($header)) { + if ($header) { return $header; } } @@ -89,12 +89,12 @@ protected function getTokenFromHeader(ServerRequestInterface $request, ?string $ * Gets the token from the request query * * @param \Psr\Http\Message\ServerRequestInterface $request The request that contains login information. - * @param string $queryParam Request query parameter name + * @param string|null $queryParam Request query parameter name * @return string|null */ protected function getTokenFromQuery(ServerRequestInterface $request, ?string $queryParam): ?string { - if (empty($queryParam)) { + if (!$queryParam) { return null; } @@ -123,7 +123,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface TokenIdentifier::CREDENTIAL_TOKEN => $token, ]); - if (empty($user)) { + if (!$user) { return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identifier->getErrors()); } diff --git a/src/UrlChecker/DefaultUrlChecker.php b/src/UrlChecker/DefaultUrlChecker.php index c8c34343..f148a02f 100644 --- a/src/UrlChecker/DefaultUrlChecker.php +++ b/src/UrlChecker/DefaultUrlChecker.php @@ -44,8 +44,7 @@ public function check(ServerRequestInterface $request, $loginUrls, array $option $options = $this->_mergeDefaultOptions($options); $urls = (array)$loginUrls; - - if (empty($urls)) { + if (!$urls) { return true; } diff --git a/src/View/Helper/IdentityHelper.php b/src/View/Helper/IdentityHelper.php index 24a94091..eca4e322 100644 --- a/src/View/Helper/IdentityHelper.php +++ b/src/View/Helper/IdentityHelper.php @@ -110,7 +110,7 @@ public function is(int|string $id, string $field = 'id'): bool */ public function get(?string $key = null): mixed { - if (empty($this->_identity)) { + if ($this->_identity === null) { return null; }