Skip to content

Commit c3b4fe3

Browse files
authored
Merge pull request #715 from cakephp/3.x-cleanup-empty
Minor cleanup.
2 parents a51f997 + de266f5 commit c3b4fe3

File tree

9 files changed

+18
-19
lines changed

9 files changed

+18
-19
lines changed

src/Authenticator/CookieAuthenticator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
8484

8585
$identity = $this->_identifier->identify(compact('username'));
8686

87-
if (empty($identity)) {
87+
if (!$identity) {
8888
return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identifier->getErrors());
8989
}
9090

src/Authenticator/EnvironmentAuthenticator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
137137
return $this->_buildLoginUrlErrorResult($request);
138138
}
139139
$data = $this->_getData($request);
140-
if (empty($data)) {
140+
if (!$data) {
141141
return new Result(null, Result::FAILURE_CREDENTIALS_MISSING, [
142142
'Environment credentials not found',
143143
]);
@@ -147,7 +147,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
147147

148148
$user = $this->_identifier->identify($data);
149149

150-
if (empty($user)) {
150+
if (!$user) {
151151
return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identifier->getErrors());
152152
}
153153

src/Authenticator/FormAuthenticator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
130130

131131
$user = $this->_identifier->identify($data);
132132

133-
if (empty($user)) {
133+
if (!$user) {
134134
return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identifier->getErrors());
135135
}
136136

src/Authenticator/HttpDigestAuthenticator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
9898
AbstractIdentifier::CREDENTIAL_USERNAME => $digest['username'],
9999
]);
100100

101-
if (empty($user)) {
101+
if (!$user) {
102102
return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND);
103103
}
104104

@@ -132,13 +132,13 @@ protected function _getDigest(ServerRequestInterface $request): ?array
132132
{
133133
$server = $request->getServerParams();
134134
$digest = empty($server['PHP_AUTH_DIGEST']) ? null : $server['PHP_AUTH_DIGEST'];
135-
if (empty($digest) && function_exists('apache_request_headers')) {
135+
if (!$digest && function_exists('apache_request_headers')) {
136136
$headers = apache_request_headers();
137137
if (!empty($headers['Authorization']) && substr($headers['Authorization'], 0, 7) === 'Digest ') {
138138
$digest = substr($headers['Authorization'], 7);
139139
}
140140
}
141-
if (empty($digest)) {
141+
if (!$digest) {
142142
return null;
143143
}
144144

@@ -165,7 +165,7 @@ public function parseAuthData(string $digest): ?array
165165
unset($req[$i[1]]);
166166
}
167167

168-
if (empty($req)) {
168+
if (!$req) {
169169
return $keys;
170170
}
171171

src/Authenticator/JwtAuthenticator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
110110
$subjectKey => $result[$subjectKey],
111111
]);
112112

113-
if (empty($user)) {
113+
if (!$user) {
114114
return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identifier->getErrors());
115115
}
116116

src/Authenticator/SessionAuthenticator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
6060
$session = $request->getAttribute('session');
6161
$user = $session->read($sessionKey);
6262

63-
if (empty($user)) {
63+
if (!$user) {
6464
return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND);
6565
}
6666

@@ -71,7 +71,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
7171
}
7272
$user = $this->_identifier->identify($credentials);
7373

74-
if (empty($user)) {
74+
if (!$user) {
7575
return new Result(null, Result::FAILURE_CREDENTIALS_INVALID);
7676
}
7777
}

src/Authenticator/TokenAuthenticator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ protected function stripTokenPrefix(string $token, string $prefix): string
7575
*/
7676
protected function getTokenFromHeader(ServerRequestInterface $request, ?string $headerLine): ?string
7777
{
78-
if (!empty($headerLine)) {
78+
if ($headerLine) {
7979
$header = $request->getHeaderLine($headerLine);
80-
if (!empty($header)) {
80+
if ($header) {
8181
return $header;
8282
}
8383
}
@@ -89,12 +89,12 @@ protected function getTokenFromHeader(ServerRequestInterface $request, ?string $
8989
* Gets the token from the request query
9090
*
9191
* @param \Psr\Http\Message\ServerRequestInterface $request The request that contains login information.
92-
* @param string $queryParam Request query parameter name
92+
* @param string|null $queryParam Request query parameter name
9393
* @return string|null
9494
*/
9595
protected function getTokenFromQuery(ServerRequestInterface $request, ?string $queryParam): ?string
9696
{
97-
if (empty($queryParam)) {
97+
if (!$queryParam) {
9898
return null;
9999
}
100100

@@ -123,7 +123,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
123123
TokenIdentifier::CREDENTIAL_TOKEN => $token,
124124
]);
125125

126-
if (empty($user)) {
126+
if (!$user) {
127127
return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identifier->getErrors());
128128
}
129129

src/UrlChecker/DefaultUrlChecker.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ public function check(ServerRequestInterface $request, $loginUrls, array $option
4444
$options = $this->_mergeDefaultOptions($options);
4545

4646
$urls = (array)$loginUrls;
47-
48-
if (empty($urls)) {
47+
if (!$urls) {
4948
return true;
5049
}
5150

src/View/Helper/IdentityHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function is(int|string $id, string $field = 'id'): bool
110110
*/
111111
public function get(?string $key = null): mixed
112112
{
113-
if (empty($this->_identity)) {
113+
if ($this->_identity === null) {
114114
return null;
115115
}
116116

0 commit comments

Comments
 (0)