Skip to content

Commit 603cc8e

Browse files
authored
Merge pull request #100 from silinternational/feature/sonar-annoyances
Address some more sonar annoyances
2 parents 61e22df + 7da953b commit 603cc8e

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

SilMock/Google/Service/Directory/Tokens.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function assertIsValidUserKey(string $userId)
5050
*/
5151
protected function isValidEmailAddress(string $email): bool
5252
{
53-
return (filter_var($email, FILTER_VALIDATE_EMAIL) !== false);
53+
return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
5454
}
5555

5656
protected function listTokensFor(string $userId): array

SilMock/Google/Service/Directory/UsersAliasesResource.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
class UsersAliasesResource extends DbClass
1313
{
14+
public const ACCOUNT_DOESNT_EXIST = "Account doesn't exist: ";
15+
1416
public function __construct(?string $dbFile = null)
1517
{
1618
parent::__construct($dbFile, 'directory', 'users_alias');
@@ -37,7 +39,7 @@ public function delete($userKey, $alias)
3739
$matchingUsers = $dir->users->get($userKey);
3840

3941
if ($matchingUsers === null) {
40-
throw new Exception("Account doesn't exist: " . $userKey, 201407101645);
42+
throw new Exception(self::ACCOUNT_DOESNT_EXIST . $userKey, 201407101645);
4143
}
4244

4345
// Get all the aliases for that user
@@ -87,7 +89,7 @@ public function insert($userKey, $postBody)
8789
$matchingUsers = $dir->users->get($userKey);
8890

8991
if ($matchingUsers === null) {
90-
throw new Exception("Account doesn't exist: " . $userKey, 201407110830);
92+
throw new Exception(self::ACCOUNT_DOESNT_EXIST . $userKey, 201407110830);
9193
}
9294

9395
if ($postBody->$key === null) {
@@ -145,7 +147,7 @@ public function listUsersAliases($userKey): ?Google_Service_Directory_Aliases
145147
$matchingUsers = $dir->users->get($userKey);
146148

147149
if ($matchingUsers === null) {
148-
throw new Exception("Account doesn't exist: " . $userKey, 201407101420);
150+
throw new Exception(self::ACCOUNT_DOESNT_EXIST . $userKey, 201407101420);
149151
}
150152

151153
$foundAliases = $this->fetchAliasesByUser($key, $userKey);

SilMock/Google/Service/Directory/UsersResource.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,20 @@ protected function getDbUserByAlias($userKey)
112112
}
113113

114114
$allUsers = $this->getAllDbUsers();
115-
116-
foreach ($allUsers as $aUser) {
117-
if (! isset($aUser['data'])) {
118-
continue;
115+
$usersWithData = array_filter(
116+
$allUsers,
117+
function ($user) {
118+
return isset($user['data']);
119119
}
120-
120+
);
121+
122+
foreach ($usersWithData as $aUser) {
121123
$userData = json_decode($aUser['data'], true);
122124
if ($userData === null) {
123125
continue;
124126
}
125127

126-
$primaryEmail = isset($userData['primaryEmail']) ? $userData['primaryEmail'] : null;
128+
$primaryEmail = $userData['primaryEmail'] ?? null;
127129

128130
$aliasesResource = $this->getAliasesForUser($primaryEmail);
129131
if ($aliasesResource) {
@@ -408,7 +410,8 @@ private function doesUserMatch($entry, $query = '')
408410
}
409411
} elseif (is_array($checkValue)) {
410412
throw new \Exception(
411-
"Did not expect something other than name as an array. Got VALUE: " . var_dump($checkValue)
413+
"Did not expect something other than name as an array. Got VALUE: "
414+
. var_export($checkValue, true)
412415
);
413416
}
414417
} elseif (isset($entry['name'][$field])) {

0 commit comments

Comments
 (0)