diff --git a/SilMock/Google/Service/Directory/Tokens.php b/SilMock/Google/Service/Directory/Tokens.php index 7a6ebb1..b3cd1ea 100644 --- a/SilMock/Google/Service/Directory/Tokens.php +++ b/SilMock/Google/Service/Directory/Tokens.php @@ -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 diff --git a/SilMock/Google/Service/Directory/UsersAliasesResource.php b/SilMock/Google/Service/Directory/UsersAliasesResource.php index d7faf8e..6168749 100644 --- a/SilMock/Google/Service/Directory/UsersAliasesResource.php +++ b/SilMock/Google/Service/Directory/UsersAliasesResource.php @@ -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'); @@ -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 @@ -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) { @@ -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); diff --git a/SilMock/Google/Service/Directory/UsersResource.php b/SilMock/Google/Service/Directory/UsersResource.php index a6bc211..7fb787e 100644 --- a/SilMock/Google/Service/Directory/UsersResource.php +++ b/SilMock/Google/Service/Directory/UsersResource.php @@ -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) { @@ -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])) {