Skip to content

Commit

Permalink
Address some more sonar annoyances
Browse files Browse the repository at this point in the history
  • Loading branch information
mtompset committed Jun 18, 2024
1 parent a5ae118 commit 7da953b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion SilMock/Google/Service/Directory/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function assertIsValidUserKey(string $userId)
*/
protected function isValidEmailAddress(string $email): bool
{
return (filter_var($email, FILTER_VALIDATE_EMAIL) !== false);
return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
}

protected function listTokensFor(string $userId): array
Expand Down
8 changes: 5 additions & 3 deletions SilMock/Google/Service/Directory/UsersAliasesResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

class UsersAliasesResource extends DbClass
{
public const ACCOUNT_DOESNT_EXIST = "Account doesn't exist: ";

public function __construct(?string $dbFile = null)
{
parent::__construct($dbFile, 'directory', 'users_alias');
Expand All @@ -37,7 +39,7 @@ public function delete($userKey, $alias)
$matchingUsers = $dir->users->get($userKey);

if ($matchingUsers === null) {
throw new Exception("Account doesn't exist: " . $userKey, 201407101645);
throw new Exception(self::ACCOUNT_DOESNT_EXIST . $userKey, 201407101645);
}

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

if ($matchingUsers === null) {
throw new Exception("Account doesn't exist: " . $userKey, 201407110830);
throw new Exception(self::ACCOUNT_DOESNT_EXIST . $userKey, 201407110830);
}

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

if ($matchingUsers === null) {
throw new Exception("Account doesn't exist: " . $userKey, 201407101420);
throw new Exception(self::ACCOUNT_DOESNT_EXIST . $userKey, 201407101420);
}

$foundAliases = $this->fetchAliasesByUser($key, $userKey);
Expand Down
17 changes: 10 additions & 7 deletions SilMock/Google/Service/Directory/UsersResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,20 @@ protected function getDbUserByAlias($userKey)
}

$allUsers = $this->getAllDbUsers();

foreach ($allUsers as $aUser) {
if (! isset($aUser['data'])) {
continue;
$usersWithData = array_filter(
$allUsers,
function ($user) {
return isset($user['data']);
}

);

foreach ($usersWithData as $aUser) {
$userData = json_decode($aUser['data'], true);
if ($userData === null) {
continue;
}

$primaryEmail = isset($userData['primaryEmail']) ? $userData['primaryEmail'] : null;
$primaryEmail = $userData['primaryEmail'] ?? null;

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

0 comments on commit 7da953b

Please sign in to comment.