From a86ad1be903d34aa675ad88d3542f5739b725147 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sat, 20 Jun 2020 14:05:43 +0300 Subject: [PATCH] Improve PHP exeution time by using fully-qualified function calls --- CONTRIBUTING.md | 10 ++ src/Appwrite/Auth/Auth.php | 20 ++-- src/Appwrite/Auth/OAuth2.php | 24 ++-- src/Appwrite/Auth/OAuth2/Amazon.php | 16 +-- src/Appwrite/Auth/OAuth2/Apple.php | 32 +++--- src/Appwrite/Auth/OAuth2/Bitbucket.php | 18 +-- src/Appwrite/Auth/OAuth2/Bitly.php | 14 +-- src/Appwrite/Auth/OAuth2/Discord.php | 16 +-- src/Appwrite/Auth/OAuth2/Dropbox.php | 12 +- src/Appwrite/Auth/OAuth2/Facebook.php | 14 +-- src/Appwrite/Auth/OAuth2/GitHub.php | 14 +-- src/Appwrite/Auth/OAuth2/Gitlab.php | 14 +-- src/Appwrite/Auth/OAuth2/Google.php | 14 +-- src/Appwrite/Auth/OAuth2/LinkedIn.php | 14 +-- src/Appwrite/Auth/OAuth2/Microsoft.php | 16 +-- src/Appwrite/Auth/OAuth2/Mock.php | 14 +-- src/Appwrite/Auth/OAuth2/Paypal.php | 18 +-- src/Appwrite/Auth/OAuth2/Salesforce.php | 18 +-- src/Appwrite/Auth/OAuth2/Slack.php | 14 +-- src/Appwrite/Auth/OAuth2/Spotify.php | 16 +-- src/Appwrite/Auth/OAuth2/Twitch.php | 14 +-- src/Appwrite/Auth/OAuth2/Vk.php | 14 +-- src/Appwrite/Auth/OAuth2/Yahoo.php | 18 +-- src/Appwrite/Auth/OAuth2/Yandex.php | 18 +-- src/Appwrite/Auth/Validator/Password.php | 2 +- src/Appwrite/Database/Adapter/MySQL.php | 106 +++++++++--------- src/Appwrite/Database/Adapter/Redis.php | 8 +- src/Appwrite/Database/Database.php | 10 +- src/Appwrite/Database/Document.php | 24 ++-- .../Database/Validator/Authorization.php | 6 +- .../Database/Validator/Collection.php | 6 +- src/Appwrite/Database/Validator/Key.php | 6 +- .../Database/Validator/Permissions.php | 6 +- src/Appwrite/Database/Validator/Structure.php | 18 +-- src/Appwrite/Database/Validator/UID.php | 2 +- src/Appwrite/Network/Validator/CNAME.php | 4 +- src/Appwrite/Network/Validator/Origin.php | 8 +- src/Appwrite/OpenSSL/OpenSSL.php | 8 +- src/Appwrite/Resize/Resize.php | 20 ++-- .../Storage/Compression/Algorithms/GZIP.php | 4 +- src/Appwrite/Storage/Device/Local.php | 58 +++++----- src/Appwrite/Storage/Device/S3.php | 2 +- src/Appwrite/Storage/Storage.php | 8 +- src/Appwrite/Storage/Validator/FileName.php | 2 +- src/Appwrite/Storage/Validator/FileType.php | 10 +- src/Appwrite/Template/Template.php | 14 +-- src/Appwrite/URL/URL.php | 8 +- 47 files changed, 371 insertions(+), 361 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 83321193d..51e405093 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -161,6 +161,16 @@ To run tests manually, run phpunit from your command line: docker exec appwrite test ``` +## Code Maintenance + +We use some automation tools to help us keep a healthy code base. + +Improve PHP exeution time by using [fully-qualified function calls](https://veewee.github.io/blog/optimizing-php-performance-by-fq-function-calls/): + +```bash +php-cs-fixer fix src/ --rules=native_function_invocation --allow-risky=yes +``` + ## Tutorials From time to time, our team will add tutorials that will help contributors find their way in the Appwrite source code. Below is a list of currently available tutorials: diff --git a/src/Appwrite/Auth/Auth.php b/src/Appwrite/Auth/Auth.php index ef787b869..634b456c7 100644 --- a/src/Appwrite/Auth/Auth.php +++ b/src/Appwrite/Auth/Auth.php @@ -82,7 +82,7 @@ class Auth */ public static function encodeSession($id, $secret) { - return base64_encode(json_encode([ + return \base64_encode(\json_encode([ 'id' => $id, 'secret' => $secret, ])); @@ -99,14 +99,14 @@ class Auth */ public static function decodeSession($session) { - $session = json_decode(base64_decode($session), true); + $session = \json_decode(\base64_decode($session), true); $default = ['id' => null, 'secret' => '']; - if (!is_array($session)) { + if (!\is_array($session)) { return $default; } - return array_merge($default, $session); + return \array_merge($default, $session); } /** @@ -120,7 +120,7 @@ class Auth */ public static function hash($string) { - return hash('sha256', $string); + return \hash('sha256', $string); } /** @@ -134,7 +134,7 @@ class Auth */ public static function passwordHash($string) { - return password_hash($string, PASSWORD_BCRYPT, array('cost' => 8)); + return \password_hash($string, PASSWORD_BCRYPT, array('cost' => 8)); } /** @@ -147,7 +147,7 @@ class Auth */ public static function passwordVerify($plain, $hash) { - return password_verify($plain, $hash); + return \password_verify($plain, $hash); } /** @@ -163,7 +163,7 @@ class Auth */ public static function passwordGenerator(int $length = 20):string { - return bin2hex(random_bytes($length)); + return \bin2hex(\random_bytes($length)); } /** @@ -179,7 +179,7 @@ class Auth */ public static function tokenGenerator(int $length = 128):string { - return bin2hex(random_bytes($length)); + return \bin2hex(\random_bytes($length)); } /** @@ -199,7 +199,7 @@ class Auth isset($token['expire']) && $token['type'] == $type && $token['secret'] === self::hash($secret) && - $token['expire'] >= time()) { + $token['expire'] >= \time()) { return $token->getId(); } } diff --git a/src/Appwrite/Auth/OAuth2.php b/src/Appwrite/Auth/OAuth2.php index 1f30d30db..8547edc75 100644 --- a/src/Appwrite/Auth/OAuth2.php +++ b/src/Appwrite/Auth/OAuth2.php @@ -95,7 +95,7 @@ abstract class OAuth2 protected function addScope(string $scope):OAuth2 { // Add a scope to the scopes array if it isn't already present - if (!in_array($scope, $this->scopes)){ + if (!\in_array($scope, $this->scopes)){ $this->scopes[] = $scope; } return $this; @@ -120,7 +120,7 @@ abstract class OAuth2 */ public function parseState(string $state) { - return json_decode($state, true); + return \json_decode($state, true); } /** @@ -133,24 +133,24 @@ abstract class OAuth2 */ protected function request(string $method, string $url = '', array $headers = [], string $payload = ''):string { - $ch = curl_init($url); + $ch = \curl_init($url); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_USERAGENT, ''); + \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); + \curl_setopt($ch, CURLOPT_HEADER, 0); + \curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + \curl_setopt($ch, CURLOPT_USERAGENT, ''); if (!empty($payload)) { - curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); + \curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); } - $headers[] = 'Content-length: '.strlen($payload); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + $headers[] = 'Content-length: '.\strlen($payload); + \curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // Send the request & save response to $response - $response = curl_exec($ch); + $response = \curl_exec($ch); - curl_close($ch); + \curl_close($ch); return $response; } diff --git a/src/Appwrite/Auth/OAuth2/Amazon.php b/src/Appwrite/Auth/OAuth2/Amazon.php index b025c3258..eb7433c1c 100644 --- a/src/Appwrite/Auth/OAuth2/Amazon.php +++ b/src/Appwrite/Auth/OAuth2/Amazon.php @@ -38,7 +38,7 @@ class Amazon extends OAuth2 */ public function parseState(string $state) { - return json_decode(html_entity_decode($state), true); + return \json_decode(\html_entity_decode($state), true); } @@ -47,11 +47,11 @@ class Amazon extends OAuth2 */ public function getLoginURL(): string { - return 'https://www.amazon.com/ap/oa?'.http_build_query([ + return 'https://www.amazon.com/ap/oa?'.\http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, - 'scope' => implode(' ', $this->getScopes()), - 'state' => json_encode($this->state), + 'scope' => \implode(' ', $this->getScopes()), + 'state' => \json_encode($this->state), 'redirect_uri' => $this->callback ]); } @@ -68,7 +68,7 @@ class Amazon extends OAuth2 'POST', 'https://api.amazon.com/auth/o2/token', $headers, - http_build_query([ + \http_build_query([ 'code' => $code, 'client_id' => $this->appID , 'client_secret' => $this->appSecret, @@ -76,7 +76,7 @@ class Amazon extends OAuth2 'grant_type' => 'authorization_code' ]) ); - $accessToken = json_decode($accessToken, true); + $accessToken = \json_decode($accessToken, true); if (isset($accessToken['access_token'])) { return $accessToken['access_token']; @@ -141,8 +141,8 @@ class Amazon extends OAuth2 protected function getUser(string $accessToken): array { if (empty($this->user)) { - $user = $this->request('GET', 'https://api.amazon.com/user/profile?access_token='.urlencode($accessToken)); - $this->user = json_decode($user, true); + $user = $this->request('GET', 'https://api.amazon.com/user/profile?access_token='.\urlencode($accessToken)); + $this->user = \json_decode($user, true); } return $this->user; } diff --git a/src/Appwrite/Auth/OAuth2/Apple.php b/src/Appwrite/Auth/OAuth2/Apple.php index 411f8baf5..9fdf2ab22 100644 --- a/src/Appwrite/Auth/OAuth2/Apple.php +++ b/src/Appwrite/Auth/OAuth2/Apple.php @@ -41,13 +41,13 @@ class Apple extends OAuth2 */ public function getLoginURL(): string { - return 'https://appleid.apple.com/auth/authorize?'.http_build_query([ + return 'https://appleid.apple.com/auth/authorize?'.\http_build_query([ 'client_id' => $this->appID, 'redirect_uri' => $this->callback, - 'state' => json_encode($this->state), + 'state' => \json_encode($this->state), 'response_type' => 'code', 'response_mode' => 'form_post', - 'scope' => implode(' ', $this->getScopes()) + 'scope' => \implode(' ', $this->getScopes()) ]); } @@ -63,7 +63,7 @@ class Apple extends OAuth2 'POST', 'https://appleid.apple.com/auth/token', $headers, - http_build_query([ + \http_build_query([ 'grant_type' => 'authorization_code', 'code' => $code, 'client_id' => $this->appID, @@ -72,10 +72,10 @@ class Apple extends OAuth2 ]) ); - $accessToken = json_decode($accessToken, true); + $accessToken = \json_decode($accessToken, true); - $this->claims = (isset($accessToken['id_token'])) ? explode('.', $accessToken['id_token']) : [0 => '', 1 => '']; - $this->claims = (isset($this->claims[1])) ? json_decode(base64_decode($this->claims[1]), true) : []; + $this->claims = (isset($accessToken['id_token'])) ? \explode('.', $accessToken['id_token']) : [0 => '', 1 => '']; + $this->claims = (isset($this->claims[1])) ? \json_decode(\base64_decode($this->claims[1]), true) : []; if (isset($accessToken['access_token'])) { return $accessToken['access_token']; @@ -135,7 +135,7 @@ class Apple extends OAuth2 protected function getAppSecret():string { try { - $secret = json_decode($this->appSecret, true); + $secret = \json_decode($this->appSecret, true); } catch (\Throwable $th) { throw new Exception('Invalid secret'); } @@ -152,19 +152,19 @@ class Apple extends OAuth2 $claims = [ 'iss' => $teamID, - 'iat' => time(), - 'exp' => time() + 86400*180, + 'iat' => \time(), + 'exp' => \time() + 86400*180, 'aud' => 'https://appleid.apple.com', 'sub' => $bundleID, ]; - $pkey = openssl_pkey_get_private($keyfile); + $pkey = \openssl_pkey_get_private($keyfile); - $payload = $this->encode(json_encode($headers)).'.'.$this->encode(json_encode($claims)); + $payload = $this->encode(\json_encode($headers)).'.'.$this->encode(\json_encode($claims)); $signature = ''; - $success = openssl_sign($payload, $signature, $pkey, OPENSSL_ALGO_SHA256); + $success = \openssl_sign($payload, $signature, $pkey, OPENSSL_ALGO_SHA256); if (!$success) return ''; @@ -176,7 +176,7 @@ class Apple extends OAuth2 */ protected function encode($data) { - return str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($data)); + return \str_replace(['+', '/', '='], ['-', '_', ''], \base64_encode($data)); } /** @@ -184,8 +184,8 @@ class Apple extends OAuth2 */ protected function retrievePositiveInteger(string $data): string { - while ('00' === mb_substr($data, 0, 2, '8bit') && mb_substr($data, 2, 2, '8bit') > '7f') { - $data = mb_substr($data, 2, null, '8bit'); + while ('00' === \mb_substr($data, 0, 2, '8bit') && \mb_substr($data, 2, 2, '8bit') > '7f') { + $data = \mb_substr($data, 2, null, '8bit'); } return $data; diff --git a/src/Appwrite/Auth/OAuth2/Bitbucket.php b/src/Appwrite/Auth/OAuth2/Bitbucket.php index 6b00cea62..ff867cbe6 100644 --- a/src/Appwrite/Auth/OAuth2/Bitbucket.php +++ b/src/Appwrite/Auth/OAuth2/Bitbucket.php @@ -32,11 +32,11 @@ class Bitbucket extends OAuth2 */ public function getLoginURL(): string { - return 'https://bitbucket.org/site/oauth2/authorize?'.http_build_query([ + return 'https://bitbucket.org/site/oauth2/authorize?'.\http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, - 'scope' => implode(' ', $this->getScopes()), - 'state' => json_encode($this->state), + 'scope' => \implode(' ', $this->getScopes()), + 'state' => \json_encode($this->state), ]); } @@ -54,7 +54,7 @@ class Bitbucket extends OAuth2 'POST', 'https://bitbucket.org/site/oauth2/access_token', $headers, - http_build_query([ + \http_build_query([ 'code' => $code, 'client_id' => $this->appID, 'client_secret' => $this->appSecret, @@ -62,7 +62,7 @@ class Bitbucket extends OAuth2 ]) ); - $accessToken = json_decode($accessToken, true); + $accessToken = \json_decode($accessToken, true); if (isset($accessToken['access_token'])) { return $accessToken['access_token']; @@ -127,11 +127,11 @@ class Bitbucket extends OAuth2 protected function getUser(string $accessToken): array { if (empty($this->user)) { - $user = $this->request('GET', 'https://api.bitbucket.org/2.0/user?access_token='.urlencode($accessToken)); - $this->user = json_decode($user, true); + $user = $this->request('GET', 'https://api.bitbucket.org/2.0/user?access_token='.\urlencode($accessToken)); + $this->user = \json_decode($user, true); - $email = $this->request('GET', 'https://api.bitbucket.org/2.0/user/emails?access_token='.urlencode($accessToken)); - $this->user['email'] = json_decode($email, true)['values'][0]['email']; + $email = $this->request('GET', 'https://api.bitbucket.org/2.0/user/emails?access_token='.\urlencode($accessToken)); + $this->user['email'] = \json_decode($email, true)['values'][0]['email']; } return $this->user; } diff --git a/src/Appwrite/Auth/OAuth2/Bitly.php b/src/Appwrite/Auth/OAuth2/Bitly.php index d6f5b5262..3da36d503 100644 --- a/src/Appwrite/Auth/OAuth2/Bitly.php +++ b/src/Appwrite/Auth/OAuth2/Bitly.php @@ -44,10 +44,10 @@ class Bitly extends OAuth2 public function getLoginURL():string { return $this->endpoint . 'authorize?'. - http_build_query([ + \http_build_query([ 'client_id' => $this->appID, 'redirect_uri' => $this->callback, - 'state' => json_encode($this->state) + 'state' => \json_encode($this->state) ]); } @@ -62,19 +62,19 @@ class Bitly extends OAuth2 'POST', $this->resourceEndpoint . 'oauth/access_token', ["Content-Type: application/x-www-form-urlencoded"], - http_build_query([ + \http_build_query([ "client_id" => $this->appID, "client_secret" => $this->appSecret, "code" => $code, "redirect_uri" => $this->callback, - "state" => json_encode($this->state) + "state" => \json_encode($this->state) ]) ); $result = null; if ($response) { - parse_str($response, $result); + \parse_str($response, $result); return $result['access_token']; } @@ -137,12 +137,12 @@ class Bitly extends OAuth2 protected function getUser(string $accessToken) { $headers = [ - 'Authorization: Bearer '. urlencode($accessToken), + 'Authorization: Bearer '. \urlencode($accessToken), "Accept: application/json" ]; if (empty($this->user)) { - $this->user = json_decode($this->request('GET', $this->resourceEndpoint . "v4/user", $headers), true); + $this->user = \json_decode($this->request('GET', $this->resourceEndpoint . "v4/user", $headers), true); } diff --git a/src/Appwrite/Auth/OAuth2/Discord.php b/src/Appwrite/Auth/OAuth2/Discord.php index 9f0320dbf..36bc102ca 100644 --- a/src/Appwrite/Auth/OAuth2/Discord.php +++ b/src/Appwrite/Auth/OAuth2/Discord.php @@ -41,11 +41,11 @@ class Discord extends OAuth2 public function getLoginURL(): string { $url = $this->endpoint . '/oauth2/authorize?'. - http_build_query([ + \http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, - 'state' => json_encode($this->state), - 'scope' => implode(' ', $this->getScopes()), + 'state' => \json_encode($this->state), + 'scope' => \implode(' ', $this->getScopes()), 'redirect_uri' => $this->callback ]); @@ -63,17 +63,17 @@ class Discord extends OAuth2 'POST', $this->endpoint . '/oauth2/token', ['Content-Type: application/x-www-form-urlencoded'], - http_build_query([ + \http_build_query([ 'grant_type' => 'authorization_code', 'code' => $code, 'redirect_uri' => $this->callback, 'client_id' => $this->appID, 'client_secret' => $this->appSecret, - 'scope' => implode(' ', $this->scope) + 'scope' => \implode(' ', $this->scope) ]) ); - $accessToken = json_decode($accessToken, true); + $accessToken = \json_decode($accessToken, true); if (isset($accessToken['access_token'])) { return $accessToken['access_token']; @@ -141,9 +141,9 @@ class Discord extends OAuth2 $user = $this->request( 'GET', $this->endpoint . '/users/@me', - ['Authorization: Bearer '.urlencode($accessToken)] + ['Authorization: Bearer '.\urlencode($accessToken)] ); - $this->user = json_decode($user, true); + $this->user = \json_decode($user, true); } return $this->user; diff --git a/src/Appwrite/Auth/OAuth2/Dropbox.php b/src/Appwrite/Auth/OAuth2/Dropbox.php index 9d6fac5c7..85567c77e 100644 --- a/src/Appwrite/Auth/OAuth2/Dropbox.php +++ b/src/Appwrite/Auth/OAuth2/Dropbox.php @@ -33,10 +33,10 @@ class Dropbox extends OAuth2 */ public function getLoginURL(): string { - return 'https://www.dropbox.com/oauth2/authorize?'.http_build_query([ + return 'https://www.dropbox.com/oauth2/authorize?'.\http_build_query([ 'client_id' => $this->appID, 'redirect_uri' => $this->callback, - 'state' => json_encode($this->state), + 'state' => \json_encode($this->state), 'response_type' => 'code' ]); } @@ -53,7 +53,7 @@ class Dropbox extends OAuth2 'POST', 'https://api.dropboxapi.com/oauth2/token', $headers, - http_build_query([ + \http_build_query([ 'code' => $code, 'client_id' => $this->appID, 'client_secret' => $this->appSecret, @@ -62,7 +62,7 @@ class Dropbox extends OAuth2 ]) ); - $accessToken = json_decode($accessToken, true); + $accessToken = \json_decode($accessToken, true); if (isset($accessToken['access_token'])) { return $accessToken['access_token']; @@ -127,9 +127,9 @@ class Dropbox extends OAuth2 protected function getUser(string $accessToken): array { if (empty($this->user)) { - $headers[] = 'Authorization: Bearer '. urlencode($accessToken); + $headers[] = 'Authorization: Bearer '. \urlencode($accessToken); $user = $this->request('POST', 'https://api.dropboxapi.com/2/users/get_current_account', $headers); - $this->user = json_decode($user, true); + $this->user = \json_decode($user, true); } return $this->user; diff --git a/src/Appwrite/Auth/OAuth2/Facebook.php b/src/Appwrite/Auth/OAuth2/Facebook.php index 673ec7f4c..6a2982242 100644 --- a/src/Appwrite/Auth/OAuth2/Facebook.php +++ b/src/Appwrite/Auth/OAuth2/Facebook.php @@ -36,11 +36,11 @@ class Facebook extends OAuth2 */ public function getLoginURL():string { - return 'https://www.facebook.com/'.$this->version.'/dialog/oauth?'.http_build_query([ + return 'https://www.facebook.com/'.$this->version.'/dialog/oauth?'.\http_build_query([ 'client_id'=> $this->appID, 'redirect_uri' => $this->callback, - 'scope' => implode(' ', $this->getScopes()), - 'state' => json_encode($this->state) + 'scope' => \implode(' ', $this->getScopes()), + 'state' => \json_encode($this->state) ]); } @@ -53,7 +53,7 @@ class Facebook extends OAuth2 { $accessToken = $this->request( 'GET', - 'https://graph.facebook.com/'.$this->version.'/oauth/access_token?'.http_build_query([ + 'https://graph.facebook.com/'.$this->version.'/oauth/access_token?'.\http_build_query([ 'client_id' => $this->appID, 'redirect_uri' => $this->callback, 'client_secret' => $this->appSecret, @@ -61,7 +61,7 @@ class Facebook extends OAuth2 ]) ); - $accessToken = json_decode($accessToken, true); + $accessToken = \json_decode($accessToken, true); if (isset($accessToken['access_token'])) { return $accessToken['access_token']; @@ -126,9 +126,9 @@ class Facebook extends OAuth2 protected function getUser(string $accessToken):array { if (empty($this->user)) { - $user = $this->request('GET', 'https://graph.facebook.com/'.$this->version.'/me?fields=email,name&access_token='.urlencode($accessToken)); + $user = $this->request('GET', 'https://graph.facebook.com/'.$this->version.'/me?fields=email,name&access_token='.\urlencode($accessToken)); - $this->user = json_decode($user, true); + $this->user = \json_decode($user, true); } return $this->user; diff --git a/src/Appwrite/Auth/OAuth2/GitHub.php b/src/Appwrite/Auth/OAuth2/GitHub.php index 445740928..9f571da3a 100644 --- a/src/Appwrite/Auth/OAuth2/GitHub.php +++ b/src/Appwrite/Auth/OAuth2/GitHub.php @@ -31,11 +31,11 @@ class Github extends OAuth2 */ public function getLoginURL():string { - return 'https://github.com/login/oauth/authorize?'. http_build_query([ + return 'https://github.com/login/oauth/authorize?'. \http_build_query([ 'client_id' => $this->appID, 'redirect_uri' => $this->callback, - 'scope' => implode(' ', $this->getScopes()), - 'state' => json_encode($this->state) + 'scope' => \implode(' ', $this->getScopes()), + 'state' => \json_encode($this->state) ]); } @@ -51,7 +51,7 @@ class Github extends OAuth2 'POST', 'https://github.com/login/oauth/access_token', [], - http_build_query([ + \http_build_query([ 'client_id' => $this->appID, 'redirect_uri' => $this->callback, 'client_secret' => $this->appSecret, @@ -61,7 +61,7 @@ class Github extends OAuth2 $output = []; - parse_str($accessToken, $output); + \parse_str($accessToken, $output); if (isset($output['access_token'])) { return $output['access_token']; @@ -93,7 +93,7 @@ class Github extends OAuth2 */ public function getUserEmail(string $accessToken):string { - $emails = json_decode($this->request('GET', 'https://api.github.com/user/emails', ['Authorization: token '.urlencode($accessToken)]), true); + $emails = \json_decode($this->request('GET', 'https://api.github.com/user/emails', ['Authorization: token '.\urlencode($accessToken)]), true); foreach ($emails as $email) { if ($email['primary'] && $email['verified']) { @@ -128,7 +128,7 @@ class Github extends OAuth2 protected function getUser(string $accessToken) { if (empty($this->user)) { - $this->user = json_decode($this->request('GET', 'https://api.github.com/user', ['Authorization: token '.urlencode($accessToken)]), true); + $this->user = \json_decode($this->request('GET', 'https://api.github.com/user', ['Authorization: token '.\urlencode($accessToken)]), true); } return $this->user; diff --git a/src/Appwrite/Auth/OAuth2/Gitlab.php b/src/Appwrite/Auth/OAuth2/Gitlab.php index fb5a3b9c4..93f27db51 100644 --- a/src/Appwrite/Auth/OAuth2/Gitlab.php +++ b/src/Appwrite/Auth/OAuth2/Gitlab.php @@ -34,11 +34,11 @@ class Gitlab extends OAuth2 */ public function getLoginURL(): string { - return 'https://gitlab.com/oauth/authorize?'.http_build_query([ + return 'https://gitlab.com/oauth/authorize?'.\http_build_query([ 'client_id' => $this->appID, 'redirect_uri' => $this->callback, - 'scope' => implode(' ', $this->getScopes()), - 'state' => json_encode($this->state), + 'scope' => \implode(' ', $this->getScopes()), + 'state' => \json_encode($this->state), 'response_type' => 'code' ]); } @@ -52,7 +52,7 @@ class Gitlab extends OAuth2 { $accessToken = $this->request( 'POST', - 'https://gitlab.com/oauth/token?'.http_build_query([ + 'https://gitlab.com/oauth/token?'.\http_build_query([ 'code' => $code, 'client_id' => $this->appID, 'client_secret' => $this->appSecret, @@ -61,7 +61,7 @@ class Gitlab extends OAuth2 ]) ); - $accessToken = json_decode($accessToken, true); + $accessToken = \json_decode($accessToken, true); if (isset($accessToken['access_token'])) { return $accessToken['access_token']; @@ -126,8 +126,8 @@ class Gitlab extends OAuth2 protected function getUser(string $accessToken): array { if (empty($this->user)) { - $user = $this->request('GET', 'https://gitlab.com/api/v4/user?access_token='.urlencode($accessToken)); - $this->user = json_decode($user, true); + $user = $this->request('GET', 'https://gitlab.com/api/v4/user?access_token='.\urlencode($accessToken)); + $this->user = \json_decode($user, true); } return $this->user; diff --git a/src/Appwrite/Auth/OAuth2/Google.php b/src/Appwrite/Auth/OAuth2/Google.php index 068ad493b..2f4a4febc 100644 --- a/src/Appwrite/Auth/OAuth2/Google.php +++ b/src/Appwrite/Auth/OAuth2/Google.php @@ -43,11 +43,11 @@ class Google extends OAuth2 */ public function getLoginURL(): string { - return 'https://accounts.google.com/o/oauth2/v2/auth?'. http_build_query([ + return 'https://accounts.google.com/o/oauth2/v2/auth?'. \http_build_query([ 'client_id' => $this->appID, 'redirect_uri' => $this->callback, - 'scope' => implode(' ', $this->getScopes()), - 'state' => json_encode($this->state), + 'scope' => \implode(' ', $this->getScopes()), + 'state' => \json_encode($this->state), 'response_type' => 'code' ]); } @@ -61,7 +61,7 @@ class Google extends OAuth2 { $accessToken = $this->request( 'POST', - 'https://oauth2.googleapis.com/token?'.http_build_query([ + 'https://oauth2.googleapis.com/token?'.\http_build_query([ 'code' => $code, 'client_id' => $this->appID, 'client_secret' => $this->appSecret, @@ -71,7 +71,7 @@ class Google extends OAuth2 ]) ); - $accessToken = json_decode($accessToken, true); + $accessToken = \json_decode($accessToken, true); if (isset($accessToken['access_token'])) { return $accessToken['access_token']; @@ -136,8 +136,8 @@ class Google extends OAuth2 protected function getUser(string $accessToken): array { if (empty($this->user)) { - $user = $this->request('GET', 'https://www.googleapis.com/oauth2/v2/userinfo?access_token='.urlencode($accessToken)); - $this->user = json_decode($user, true); + $user = $this->request('GET', 'https://www.googleapis.com/oauth2/v2/userinfo?access_token='.\urlencode($accessToken)); + $this->user = \json_decode($user, true); } return $this->user; diff --git a/src/Appwrite/Auth/OAuth2/LinkedIn.php b/src/Appwrite/Auth/OAuth2/LinkedIn.php index 46c553ffc..d2315980b 100644 --- a/src/Appwrite/Auth/OAuth2/LinkedIn.php +++ b/src/Appwrite/Auth/OAuth2/LinkedIn.php @@ -45,12 +45,12 @@ class LinkedIn extends OAuth2 */ public function getLoginURL():string { - return 'https://www.linkedin.com/oauth/v2/authorization?'.http_build_query([ + return 'https://www.linkedin.com/oauth/v2/authorization?'.\http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, 'redirect_uri' => $this->callback, - 'scope' => implode(' ', $this->getScopes()), - 'state' => json_encode($this->state), + 'scope' => \implode(' ', $this->getScopes()), + 'state' => \json_encode($this->state), ]); } @@ -65,7 +65,7 @@ class LinkedIn extends OAuth2 'POST', 'https://www.linkedin.com/oauth/v2/accessToken', ['Content-Type: application/x-www-form-urlencoded'], - http_build_query([ + \http_build_query([ 'grant_type' => 'authorization_code', 'code' => $code, 'redirect_uri' => $this->callback, @@ -74,7 +74,7 @@ class LinkedIn extends OAuth2 ]) ); - $accessToken = json_decode($accessToken, true); + $accessToken = \json_decode($accessToken, true); if (isset($accessToken['access_token'])) { return $accessToken['access_token']; @@ -106,7 +106,7 @@ class LinkedIn extends OAuth2 */ public function getUserEmail(string $accessToken):string { - $email = json_decode($this->request('GET', 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))', ['Authorization: Bearer '.urlencode($accessToken)]), true); + $email = \json_decode($this->request('GET', 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))', ['Authorization: Bearer '.\urlencode($accessToken)]), true); if ( isset($email['elements']) && @@ -149,7 +149,7 @@ class LinkedIn extends OAuth2 protected function getUser(string $accessToken) { if (empty($this->user)) { - $this->user = json_decode($this->request('GET', 'https://api.linkedin.com/v2/me', ['Authorization: Bearer '.urlencode($accessToken)]), true); + $this->user = \json_decode($this->request('GET', 'https://api.linkedin.com/v2/me', ['Authorization: Bearer '.\urlencode($accessToken)]), true); } return $this->user; diff --git a/src/Appwrite/Auth/OAuth2/Microsoft.php b/src/Appwrite/Auth/OAuth2/Microsoft.php index 86f435ac3..8f543c796 100644 --- a/src/Appwrite/Auth/OAuth2/Microsoft.php +++ b/src/Appwrite/Auth/OAuth2/Microsoft.php @@ -36,11 +36,11 @@ class Microsoft extends OAuth2 */ public function getLoginURL(): string { - return 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?'.http_build_query([ + return 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?'.\http_build_query([ 'client_id' => $this->appID, 'redirect_uri' => $this->callback, - 'state'=> json_encode($this->state), - 'scope'=> implode(' ', $this->getScopes()), + 'state'=> \json_encode($this->state), + 'scope'=> \implode(' ', $this->getScopes()), 'response_type' => 'code', 'response_mode' => 'query' ]); @@ -59,17 +59,17 @@ class Microsoft extends OAuth2 'POST', 'https://login.microsoftonline.com/common/oauth2/v2.0/token', $headers, - http_build_query([ + \http_build_query([ 'code' => $code, 'client_id' => $this->appID, 'client_secret' => $this->appSecret, 'redirect_uri' => $this->callback, - 'scope' => implode(' ', $this->getScopes()), + 'scope' => \implode(' ', $this->getScopes()), 'grant_type' => 'authorization_code' ]) ); - $accessToken = json_decode($accessToken, true); + $accessToken = \json_decode($accessToken, true); if (isset($accessToken['access_token'])) { return $accessToken['access_token']; @@ -134,9 +134,9 @@ class Microsoft extends OAuth2 protected function getUser(string $accessToken): array { if (empty($this->user)) { - $headers[] = 'Authorization: Bearer '. urlencode($accessToken); + $headers[] = 'Authorization: Bearer '. \urlencode($accessToken); $user = $this->request('GET', 'https://graph.microsoft.com/v1.0/me', $headers); - $this->user = json_decode($user, true); + $this->user = \json_decode($user, true); } return $this->user; diff --git a/src/Appwrite/Auth/OAuth2/Mock.php b/src/Appwrite/Auth/OAuth2/Mock.php index 9f931b957..e1744343f 100644 --- a/src/Appwrite/Auth/OAuth2/Mock.php +++ b/src/Appwrite/Auth/OAuth2/Mock.php @@ -36,11 +36,11 @@ class Mock extends OAuth2 */ public function getLoginURL():string { - return 'http://localhost/'.$this->version.'/mock/tests/general/oauth2?'. http_build_query([ + return 'http://localhost/'.$this->version.'/mock/tests/general/oauth2?'. \http_build_query([ 'client_id' => $this->appID, 'redirect_uri' => $this->callback, - 'scope' => implode(' ', $this->getScopes()), - 'state' => json_encode($this->state) + 'scope' => \implode(' ', $this->getScopes()), + 'state' => \json_encode($this->state) ]); } @@ -54,7 +54,7 @@ class Mock extends OAuth2 $accessToken = $this->request( 'GET', 'http://localhost/'.$this->version.'/mock/tests/general/oauth2/token?'. - http_build_query([ + \http_build_query([ 'client_id' => $this->appID, 'redirect_uri' => $this->callback, 'client_secret' => $this->appSecret, @@ -62,7 +62,7 @@ class Mock extends OAuth2 ]) ); - $accessToken = json_decode($accessToken, true); // + $accessToken = \json_decode($accessToken, true); // if (isset($accessToken['access_token'])) { return $accessToken['access_token']; @@ -127,9 +127,9 @@ class Mock extends OAuth2 protected function getUser(string $accessToken):array { if (empty($this->user)) { - $user = $this->request('GET', 'http://localhost/'.$this->version.'/mock/tests/general/oauth2/user?token='.urlencode($accessToken)); + $user = $this->request('GET', 'http://localhost/'.$this->version.'/mock/tests/general/oauth2/user?token='.\urlencode($accessToken)); - $this->user = json_decode($user, true); + $this->user = \json_decode($user, true); } return $this->user; diff --git a/src/Appwrite/Auth/OAuth2/Paypal.php b/src/Appwrite/Auth/OAuth2/Paypal.php index b87973c48..ef05a1aff 100644 --- a/src/Appwrite/Auth/OAuth2/Paypal.php +++ b/src/Appwrite/Auth/OAuth2/Paypal.php @@ -50,14 +50,14 @@ class Paypal extends OAuth2 public function getLoginURL(): string { $url = $this->endpoint[$this->environment] . 'connect/?'. - http_build_query([ + \http_build_query([ 'flowEntry' => 'static', 'response_type' => 'code', 'client_id' => $this->appID, - 'scope' => implode(' ', $this->getScopes()), + 'scope' => \implode(' ', $this->getScopes()), // paypal is not accepting localhost string into return uri - 'redirect_uri' => str_replace("localhost", "127.0.0.1", $this->callback), - 'state' => json_encode($this->state), + 'redirect_uri' => \str_replace("localhost", "127.0.0.1", $this->callback), + 'state' => \json_encode($this->state), ]); return $url; @@ -73,15 +73,15 @@ class Paypal extends OAuth2 $accessToken = $this->request( 'POST', $this->resourceEndpoint[$this->environment] . 'oauth2/token', - ['Authorization: Basic ' . base64_encode($this->appID . ':' . $this->appSecret)], - http_build_query([ + ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)], + \http_build_query([ 'code' => $code, 'grant_type' => 'authorization_code', ]) ); - $accessToken = json_decode($accessToken, true); + $accessToken = \json_decode($accessToken, true); if (isset($accessToken['access_token'])) { @@ -148,7 +148,7 @@ class Paypal extends OAuth2 { $header = [ 'Content-Type: application/json', - 'Authorization: Bearer '.urlencode($accessToken), + 'Authorization: Bearer '.\urlencode($accessToken), ]; if (empty($this->user)) { $user = $this->request( @@ -156,7 +156,7 @@ class Paypal extends OAuth2 $this->resourceEndpoint[$this->environment] . 'identity/oauth2/userinfo?schema=paypalv1.1', $header ); - $this->user = json_decode($user, true); + $this->user = \json_decode($user, true); } return $this->user; diff --git a/src/Appwrite/Auth/OAuth2/Salesforce.php b/src/Appwrite/Auth/OAuth2/Salesforce.php index 478e05529..7e6467d33 100644 --- a/src/Appwrite/Auth/OAuth2/Salesforce.php +++ b/src/Appwrite/Auth/OAuth2/Salesforce.php @@ -38,7 +38,7 @@ class Salesforce extends OAuth2 */ public function parseState(string $state) { - return json_decode(html_entity_decode($state), true); + return \json_decode(\html_entity_decode($state), true); } @@ -47,12 +47,12 @@ class Salesforce extends OAuth2 */ public function getLoginURL(): string { - return 'https://login.salesforce.com/services/oauth2/authorize?'.http_build_query([ + return 'https://login.salesforce.com/services/oauth2/authorize?'.\http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, 'redirect_uri'=> $this->callback, - 'scope'=> implode(' ', $this->getScopes()), - 'state' => json_encode($this->state) + 'scope'=> \implode(' ', $this->getScopes()), + 'state' => \json_encode($this->state) ]); } @@ -64,7 +64,7 @@ class Salesforce extends OAuth2 public function getAccessToken(string $code): string { $headers = [ - "Authorization: Basic " . base64_encode($this->appID . ":" . $this->appSecret), + "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret), "Content-Type: application/x-www-form-urlencoded", ]; @@ -72,13 +72,13 @@ class Salesforce extends OAuth2 'POST', 'https://login.salesforce.com/services/oauth2/token', $headers, - http_build_query([ + \http_build_query([ 'code' => $code, 'redirect_uri' => $this->callback , 'grant_type' => 'authorization_code' ]) ); - $accessToken = json_decode($accessToken, true); + $accessToken = \json_decode($accessToken, true); if (isset($accessToken['access_token'])) { return $accessToken['access_token']; @@ -143,8 +143,8 @@ class Salesforce extends OAuth2 protected function getUser(string $accessToken): array { if (empty($this->user)) { - $user = $this->request('GET', 'https://login.salesforce.com/services/oauth2/userinfo?access_token='.urlencode($accessToken)); - $this->user = json_decode($user, true); + $user = $this->request('GET', 'https://login.salesforce.com/services/oauth2/userinfo?access_token='.\urlencode($accessToken)); + $this->user = \json_decode($user, true); } return $this->user; } diff --git a/src/Appwrite/Auth/OAuth2/Slack.php b/src/Appwrite/Auth/OAuth2/Slack.php index 87d562655..684804686 100644 --- a/src/Appwrite/Auth/OAuth2/Slack.php +++ b/src/Appwrite/Auth/OAuth2/Slack.php @@ -35,11 +35,11 @@ class Slack extends OAuth2 public function getLoginURL():string { // https://api.slack.com/docs/oauth#step_1_-_sending_users_to_authorize_and_or_install - return 'https://slack.com/oauth/authorize?'.http_build_query([ + return 'https://slack.com/oauth/authorize?'.\http_build_query([ 'client_id'=> $this->appID, - 'scope' => implode(' ', $this->getScopes()), + 'scope' => \implode(' ', $this->getScopes()), 'redirect_uri' => $this->callback, - 'state' => json_encode($this->state) + 'state' => \json_encode($this->state) ]); } @@ -53,7 +53,7 @@ class Slack extends OAuth2 // https://api.slack.com/docs/oauth#step_3_-_exchanging_a_verification_code_for_an_access_token $accessToken = $this->request( 'GET', - 'https://slack.com/api/oauth.access?'.http_build_query([ + 'https://slack.com/api/oauth.access?'.\http_build_query([ 'client_id' => $this->appID, 'client_secret' => $this->appSecret, 'code' => $code, @@ -61,7 +61,7 @@ class Slack extends OAuth2 ]) ); - $accessToken = json_decode($accessToken, true); // + $accessToken = \json_decode($accessToken, true); // if (isset($accessToken['access_token'])) { return $accessToken['access_token']; @@ -130,10 +130,10 @@ class Slack extends OAuth2 // https://api.slack.com/methods/users.identity $user = $this->request( 'GET', - 'https://slack.com/api/users.identity?token='.urlencode($accessToken) + 'https://slack.com/api/users.identity?token='.\urlencode($accessToken) ); - $this->user = json_decode($user, true); + $this->user = \json_decode($user, true); } return $this->user; diff --git a/src/Appwrite/Auth/OAuth2/Spotify.php b/src/Appwrite/Auth/OAuth2/Spotify.php index bb3fafd4e..1bc3d5190 100644 --- a/src/Appwrite/Auth/OAuth2/Spotify.php +++ b/src/Appwrite/Auth/OAuth2/Spotify.php @@ -46,12 +46,12 @@ class Spotify extends OAuth2 public function getLoginURL():string { return $this->endpoint . 'authorize?'. - http_build_query([ + \http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, - 'scope' => implode(' ', $this->getScopes()), + 'scope' => \implode(' ', $this->getScopes()), 'redirect_uri' => $this->callback, - 'state' => json_encode($this->state) + 'state' => \json_encode($this->state) ]); } @@ -62,12 +62,12 @@ class Spotify extends OAuth2 */ public function getAccessToken(string $code):string { - $header = "Authorization: Basic " . base64_encode($this->appID . ":" . $this->appSecret); - $result = json_decode($this->request( + $header = "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret); + $result = \json_decode($this->request( 'POST', $this->endpoint . 'api/token', [$header], - http_build_query([ + \http_build_query([ "code" => $code, "grant_type" => "authorization_code", "redirect_uri" => $this->callback @@ -137,8 +137,8 @@ class Spotify extends OAuth2 protected function getUser(string $accessToken) { if (empty($this->user)) { - $this->user = json_decode($this->request('GET', - $this->resourceEndpoint . "me", ['Authorization: Bearer '.urlencode($accessToken)]), true); + $this->user = \json_decode($this->request('GET', + $this->resourceEndpoint . "me", ['Authorization: Bearer '.\urlencode($accessToken)]), true); } return $this->user; diff --git a/src/Appwrite/Auth/OAuth2/Twitch.php b/src/Appwrite/Auth/OAuth2/Twitch.php index fa7adfcd1..94f735b50 100644 --- a/src/Appwrite/Auth/OAuth2/Twitch.php +++ b/src/Appwrite/Auth/OAuth2/Twitch.php @@ -46,13 +46,13 @@ class Twitch extends OAuth2 public function getLoginURL():string { return $this->endpoint . 'authorize?'. - http_build_query([ + \http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, - 'scope' => implode(' ', $this->getScopes()), + 'scope' => \implode(' ', $this->getScopes()), 'redirect_uri' => $this->callback, 'force_verify' => true, - 'state' => json_encode($this->state) + 'state' => \json_encode($this->state) ]); } @@ -63,11 +63,11 @@ class Twitch extends OAuth2 */ public function getAccessToken(string $code):string { - $result = json_decode($this->request( + $result = \json_decode($this->request( 'POST', $this->endpoint . 'token', [], - http_build_query([ + \http_build_query([ "client_id" => $this->appID, "client_secret" => $this->appSecret, "code" => $code, @@ -139,8 +139,8 @@ class Twitch extends OAuth2 protected function getUser(string $accessToken) { if (empty($this->user)) { - $this->user = json_decode($this->request('GET', - $this->resourceEndpoint, ['Authorization: Bearer '.urlencode($accessToken)]), true)['data']['0']; + $this->user = \json_decode($this->request('GET', + $this->resourceEndpoint, ['Authorization: Bearer '.\urlencode($accessToken)]), true)['data']['0']; } return $this->user; diff --git a/src/Appwrite/Auth/OAuth2/Vk.php b/src/Appwrite/Auth/OAuth2/Vk.php index 6e9d6fcf7..11e1fd4f0 100644 --- a/src/Appwrite/Auth/OAuth2/Vk.php +++ b/src/Appwrite/Auth/OAuth2/Vk.php @@ -44,13 +44,13 @@ class Vk extends OAuth2 */ public function getLoginURL(): string { - return 'https://oauth.vk.com/authorize?' . http_build_query([ + return 'https://oauth.vk.com/authorize?' . \http_build_query([ 'client_id' => $this->appID, 'redirect_uri' => $this->callback, 'response_type' => 'code', - 'state' => json_encode($this->state), + 'state' => \json_encode($this->state), 'v' => $this->version, - 'scope' => implode(' ', $this->getScopes()) + 'scope' => \implode(' ', $this->getScopes()) ]); } @@ -66,14 +66,14 @@ class Vk extends OAuth2 'POST', 'https://oauth.vk.com/access_token?', $headers, - http_build_query([ + \http_build_query([ 'code' => $code, 'client_id' => $this->appID, 'client_secret' => $this->appSecret, 'redirect_uri' => $this->callback ]) ); - $accessToken = json_decode($accessToken, true); + $accessToken = \json_decode($accessToken, true); if (isset($accessToken['email'])) { $this->user['email'] = $accessToken['email']; @@ -147,14 +147,14 @@ class Vk extends OAuth2 if (empty($this->user['name'])) { $user = $this->request( 'GET', - 'https://api.vk.com/method/users.get?'. http_build_query([ + 'https://api.vk.com/method/users.get?'. \http_build_query([ 'v' => $this->version, 'fields' => 'id,name,email,first_name,last_name', 'access_token' => $accessToken ]) ); - $user = json_decode($user, true); + $user = \json_decode($user, true); $this->user['name'] = $user['response'][0]['first_name'] ." ".$user['response'][0]['last_name']; } return $this->user; diff --git a/src/Appwrite/Auth/OAuth2/Yahoo.php b/src/Appwrite/Auth/OAuth2/Yahoo.php index 46d83f18c..41100132f 100644 --- a/src/Appwrite/Auth/OAuth2/Yahoo.php +++ b/src/Appwrite/Auth/OAuth2/Yahoo.php @@ -49,7 +49,7 @@ class Yahoo extends OAuth2 */ public function parseState(string $state) { - return json_decode(html_entity_decode($state), true); + return \json_decode(\html_entity_decode($state), true); } /** @@ -58,12 +58,12 @@ class Yahoo extends OAuth2 public function getLoginURL():string { return $this->endpoint . 'request_auth?'. - http_build_query([ + \http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, - 'scope' => implode(' ', $this->getScopes()), + 'scope' => \implode(' ', $this->getScopes()), 'redirect_uri' => $this->callback, - 'state' => json_encode($this->state) + 'state' => \json_encode($this->state) ]); } @@ -75,15 +75,15 @@ class Yahoo extends OAuth2 public function getAccessToken(string $code):string { $header = [ - "Authorization: Basic " . base64_encode($this->appID . ":" . $this->appSecret), + "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret), "Content-Type: application/x-www-form-urlencoded", ]; - $result = json_decode($this->request( + $result = \json_decode($this->request( 'POST', $this->endpoint . 'get_token', $header, - http_build_query([ + \http_build_query([ "code" => $code, "grant_type" => "authorization_code", "redirect_uri" => $this->callback @@ -153,8 +153,8 @@ class Yahoo extends OAuth2 protected function getUser(string $accessToken) { if (empty($this->user)) { - $this->user = json_decode($this->request('GET', - $this->resourceEndpoint, ['Authorization: Bearer '.urlencode($accessToken)]), true); + $this->user = \json_decode($this->request('GET', + $this->resourceEndpoint, ['Authorization: Bearer '.\urlencode($accessToken)]), true); } return $this->user; diff --git a/src/Appwrite/Auth/OAuth2/Yandex.php b/src/Appwrite/Auth/OAuth2/Yandex.php index 138862d18..7955d33fd 100644 --- a/src/Appwrite/Auth/OAuth2/Yandex.php +++ b/src/Appwrite/Auth/OAuth2/Yandex.php @@ -36,7 +36,7 @@ class Yandex extends OAuth2 */ public function parseState(string $state) { - return json_decode(html_entity_decode($state), true); + return \json_decode(\html_entity_decode($state), true); } @@ -45,11 +45,11 @@ class Yandex extends OAuth2 */ public function getLoginURL(): string { - return 'https://oauth.yandex.com/authorize?'.http_build_query([ + return 'https://oauth.yandex.com/authorize?'.\http_build_query([ 'response_type' => 'code', 'client_id' => $this->appID, - 'scope'=> implode(' ', $this->getScopes()), - 'state' => json_encode($this->state) + 'scope'=> \implode(' ', $this->getScopes()), + 'state' => \json_encode($this->state) ]); } @@ -61,7 +61,7 @@ class Yandex extends OAuth2 public function getAccessToken(string $code): string { $headers = [ - "Authorization: Basic " . base64_encode($this->appID . ":" . $this->appSecret), + "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret), "Content-Type: application/x-www-form-urlencoded", ]; @@ -69,12 +69,12 @@ class Yandex extends OAuth2 'POST', 'https://oauth.yandex.com/token', $headers, - http_build_query([ + \http_build_query([ 'code' => $code, 'grant_type' => 'authorization_code' ]) ); - $accessToken = json_decode($accessToken, true); + $accessToken = \json_decode($accessToken, true); if (isset($accessToken['access_token'])) { return $accessToken['access_token']; @@ -139,11 +139,11 @@ class Yandex extends OAuth2 protected function getUser(string $accessToken): array { if (empty($this->user)) { - $user = $this->request('GET', 'https://login.yandex.ru/info?'.http_build_query([ + $user = $this->request('GET', 'https://login.yandex.ru/info?'.\http_build_query([ 'format' => 'json', 'oauth_token' => $accessToken ])); - $this->user = json_decode($user, true); + $this->user = \json_decode($user, true); } return $this->user; } diff --git a/src/Appwrite/Auth/Validator/Password.php b/src/Appwrite/Auth/Validator/Password.php index 494da67fb..3afcbe7aa 100644 --- a/src/Appwrite/Auth/Validator/Password.php +++ b/src/Appwrite/Auth/Validator/Password.php @@ -34,7 +34,7 @@ class Password extends Validator */ public function isValid($value) { - if (strlen($value) < 6 || strlen($value) > 32) { + if (\strlen($value) < 6 || \strlen($value) > 32) { return false; } diff --git a/src/Appwrite/Database/Adapter/MySQL.php b/src/Appwrite/Database/Adapter/MySQL.php index 6c90c64a7..461d2a29e 100644 --- a/src/Appwrite/Database/Adapter/MySQL.php +++ b/src/Appwrite/Database/Adapter/MySQL.php @@ -113,11 +113,11 @@ class MySQL extends Adapter $output = [ '$id' => null, '$collection' => null, - '$permissions' => (!empty($document['permissions'])) ? json_decode($document['permissions'], true) : [], + '$permissions' => (!empty($document['permissions'])) ? \json_decode($document['permissions'], true) : [], ]; foreach ($properties as &$property) { - settype($property['value'], $property['primitive']); + \settype($property['value'], $property['primitive']); if ($property['array']) { $output[$property['key']][] = $property['value']; @@ -154,9 +154,9 @@ class MySQL extends Adapter public function createDocument(array $data = [], array $unique = []) { $order = 0; - $data = array_merge(['$id' => null, '$permissions' => []], $data); // Merge data with default params - $signature = md5(json_encode($data, true)); - $revision = uniqid('', true); + $data = \array_merge(['$id' => null, '$permissions' => []], $data); // Merge data with default params + $signature = \md5(\json_encode($data, true)); + $revision = \uniqid('', true); $data['$id'] = (empty($data['$id'])) ? null : $data['$id']; /* @@ -192,7 +192,7 @@ class MySQL extends Adapter SET `key` = :key; '); - $st->bindValue(':key', md5($data['$collection'].':'.$key.'='.$value), PDO::PARAM_STR); + $st->bindValue(':key', \md5($data['$collection'].':'.$key.'='.$value), PDO::PARAM_STR); if(!$st->execute()) { throw new Duplicate('Duplicated Property: '.$key.'='.$value); @@ -213,9 +213,9 @@ class MySQL extends Adapter $st1->bindValue(':uid', $data['$id'], PDO::PARAM_STR); $st1->bindValue(':revision', $revision, PDO::PARAM_STR); $st1->bindValue(':signature', $signature, PDO::PARAM_STR); - $st1->bindValue(':createdAt', date('Y-m-d H:i:s', time()), PDO::PARAM_STR); - $st1->bindValue(':updatedAt', date('Y-m-d H:i:s', time()), PDO::PARAM_STR); - $st1->bindValue(':permissions', json_encode($data['$permissions']), PDO::PARAM_STR); + $st1->bindValue(':createdAt', \date('Y-m-d H:i:s', \time()), PDO::PARAM_STR); + $st1->bindValue(':updatedAt', \date('Y-m-d H:i:s', \time()), PDO::PARAM_STR); + $st1->bindValue(':permissions', \json_encode($data['$permissions']), PDO::PARAM_STR); $st1->execute(); @@ -240,7 +240,7 @@ class MySQL extends Adapter foreach ($data as $key => $value) { // Prepare properties data - if (in_array($key, ['$permissions'])) { + if (\in_array($key, ['$permissions'])) { continue; } @@ -292,8 +292,8 @@ class MySQL extends Adapter } foreach ($props as $prop) { - if (is_array($prop['value'])) { - throw new Exception('Value can\'t be an array: '.json_encode($prop['value'])); + if (\is_array($prop['value'])) { + throw new Exception('Value can\'t be an array: '.\json_encode($prop['value'])); } $st2->bindValue(':documentUid', $data['$id'], PDO::PARAM_STR); $st2->bindValue(':documentRevision', $revision, PDO::PARAM_STR); @@ -481,7 +481,7 @@ class MySQL extends Adapter */ public function getCollection(array $options) { - $start = microtime(true); + $start = \microtime(true); $orderCastMap = [ 'int' => 'UNSIGNED', 'string' => 'CHAR', @@ -494,11 +494,11 @@ class MySQL extends Adapter $options['orderField'] = (empty($options['orderField'])) ? '$id' : $options['orderField']; // Set default order field $options['orderCast'] = (empty($options['orderCast'])) ? 'string' : $options['orderCast']; // Set default order field - if (!array_key_exists($options['orderCast'], $orderCastMap)) { + if (!\array_key_exists($options['orderCast'], $orderCastMap)) { throw new Exception('Invalid order cast'); } - if (!in_array($options['orderType'], $orderTypeMap)) { + if (!\in_array($options['orderType'], $orderTypeMap)) { throw new Exception('Invalid order type'); } @@ -514,11 +514,11 @@ class MySQL extends Adapter $value = $filter['value']; $operator = $filter['operator']; - $path = explode('.', $key); + $path = \explode('.', $key); $original = $path; - if (1 < count($path)) { - $key = array_pop($path); + if (1 < \count($path)) { + $key = \array_pop($path); } else { $path = []; } @@ -535,7 +535,7 @@ class MySQL extends Adapter //if($path == "''") { // Handle direct attributes queries $where[] = 'JOIN `'.$this->getNamespace().".database.properties` b{$i} ON a.uid IS NOT NULL AND b{$i}.documentUid = a.uid AND (b{$i}.key = {$key} AND b{$i}.value {$operator} {$value})"; } else { // Handle direct child attributes queries - $len = count($original); + $len = \count($original); $prev = 'c'.$i; foreach ($original as $y => $part) { @@ -557,10 +557,10 @@ class MySQL extends Adapter } // Sorting - $orderPath = explode('.', $options['orderField']); - $len = count($orderPath); + $orderPath = \explode('.', $options['orderField']); + $len = \count($orderPath); $orderKey = 'order_b'; - $part = $this->getPDO()->quote(implode('', $orderPath), PDO::PARAM_STR); + $part = $this->getPDO()->quote(\implode('', $orderPath), PDO::PARAM_STR); $orderSelect = "CASE WHEN {$orderKey}.key = {$part} THEN CAST({$orderKey}.value AS {$orderCastMap[$options['orderCast']]}) END AS sort_ff"; if (1 === $len) { @@ -606,9 +606,9 @@ class MySQL extends Adapter } $select = 'DISTINCT a.uid'; - $where = implode("\n", $where); - $join = implode("\n", $join); - $sorts = implode("\n", $sorts); + $where = \implode("\n", $where); + $join = \implode("\n", $join); + $sorts = \implode("\n", $sorts); $range = "LIMIT {$options['offset']}, {$options['limit']}"; $roles = []; @@ -624,10 +624,10 @@ class MySQL extends Adapter FROM `".$this->getNamespace().".database.documents` a {$where}{$join}{$sorts} WHERE status = 0 {$search} - AND (".implode('||', $roles).") + AND (".\implode('||', $roles).") ORDER BY sort_ff {$options['orderType']} %s"; - $st = $this->getPDO()->prepare(sprintf($query, $select, $range)); + $st = $this->getPDO()->prepare(\sprintf($query, $select, $range)); $st->execute(); @@ -638,7 +638,7 @@ class MySQL extends Adapter $results['data'][] = $node['uid']; } - $count = $this->getPDO()->prepare(sprintf($query, 'count(DISTINCT a.uid) as sum', '')); + $count = $this->getPDO()->prepare(\sprintf($query, 'count(DISTINCT a.uid) as sum', '')); $count->execute(); @@ -647,11 +647,11 @@ class MySQL extends Adapter $this->resetDebug(); $this - ->setDebug('query', preg_replace('/\s+/', ' ', sprintf($query, $select, $range))) - ->setDebug('time', microtime(true) - $start) - ->setDebug('filters', count($options['filters'])) - ->setDebug('joins', substr_count($query, 'JOIN')) - ->setDebug('count', count($results['data'])) + ->setDebug('query', \preg_replace('/\s+/', ' ', \sprintf($query, $select, $range))) + ->setDebug('time', \microtime(true) - $start) + ->setDebug('filters', \count($options['filters'])) + ->setDebug('joins', \substr_count($query, 'JOIN')) + ->setDebug('count', \count($results['data'])) ->setDebug('sum', (int) $count['sum']) ->setDebug('documents', $this->count) ; @@ -670,7 +670,7 @@ class MySQL extends Adapter */ public function getCount(array $options) { - $start = microtime(true); + $start = \microtime(true); $where = []; $join = []; @@ -680,11 +680,11 @@ class MySQL extends Adapter $key = $filter['key']; $value = $filter['value']; $operator = $filter['operator']; - $path = explode('.', $key); + $path = \explode('.', $key); $original = $path; - if (1 < count($path)) { - $key = array_pop($path); + if (1 < \count($path)) { + $key = \array_pop($path); } else { $path = []; } @@ -696,7 +696,7 @@ class MySQL extends Adapter //if($path == "''") { // Handle direct attributes queries $where[] = 'JOIN `'.$this->getNamespace().".database.properties` b{$i} ON a.uid IS NOT NULL AND b{$i}.documentUid = a.uid AND (b{$i}.key = {$key} AND b{$i}.value {$operator} {$value})"; } else { // Handle direct child attributes queries - $len = count($original); + $len = \count($original); $prev = 'c'.$i; foreach ($original as $y => $part) { @@ -714,8 +714,8 @@ class MySQL extends Adapter } } - $where = implode("\n", $where); - $join = implode("\n", $join); + $where = \implode("\n", $where); + $join = \implode("\n", $join); $func = 'JOIN `'.$this->getNamespace().".database.properties` b_func ON a.uid IS NOT NULL AND a.uid = b_func.documentUid AND (b_func.key = 'sizeOriginal')"; @@ -732,9 +732,9 @@ class MySQL extends Adapter $query = 'SELECT SUM(b_func.value) as result FROM `'.$this->getNamespace().".database.documents` a {$where}{$join}{$func} WHERE status = 0 - AND (".implode('||', $roles).')'; + AND (".\implode('||', $roles).')'; - $st = $this->getPDO()->prepare(sprintf($query)); + $st = $this->getPDO()->prepare(\sprintf($query)); $st->execute(); @@ -743,10 +743,10 @@ class MySQL extends Adapter $this->resetDebug(); $this - ->setDebug('query', preg_replace('/\s+/', ' ', sprintf($query))) - ->setDebug('time', microtime(true) - $start) - ->setDebug('filters', count($options['filters'])) - ->setDebug('joins', substr_count($query, 'JOIN')) + ->setDebug('query', \preg_replace('/\s+/', ' ', \sprintf($query))) + ->setDebug('time', \microtime(true) - $start) + ->setDebug('filters', \count($options['filters'])) + ->setDebug('joins', \substr_count($query, 'JOIN')) ; return (int) (isset($result['result'])) ? $result['result'] : 0; @@ -757,7 +757,7 @@ class MySQL extends Adapter */ public function getId() { - $unique = uniqid(); + $unique = \uniqid(); $attempts = 5; for ($i = 1; $i <= $attempts; ++$i) { @@ -801,7 +801,7 @@ class MySQL extends Adapter $operator = null; foreach ($operatorsMap as $node) { - if (strpos($filter, $node) !== false) { + if (\strpos($filter, $node) !== false) { $operator = $node; break; } @@ -811,9 +811,9 @@ class MySQL extends Adapter throw new Exception('Invalid operator'); } - $filter = explode($operator, $filter); + $filter = \explode($operator, $filter); - if (count($filter) != 2) { + if (\count($filter) != 2) { throw new Exception('Invalid filter expression'); } @@ -838,7 +838,7 @@ class MySQL extends Adapter */ protected function getDataType($value) { - switch (gettype($value)) { + switch (\gettype($value)) { case 'string': return self::DATA_TYPE_STRING; @@ -857,7 +857,7 @@ class MySQL extends Adapter break; case 'array': - if ((bool) count(array_filter(array_keys($value), 'is_string'))) { + if ((bool) \count(\array_filter(\array_keys($value), 'is_string'))) { return self::DATA_TYPE_DICTIONARY; } @@ -869,7 +869,7 @@ class MySQL extends Adapter break; } - throw new Exception('Unknown data type: '.$value.' ('.gettype($value).')'); + throw new Exception('Unknown data type: '.$value.' ('.\gettype($value).')'); } /** diff --git a/src/Appwrite/Database/Adapter/Redis.php b/src/Appwrite/Database/Adapter/Redis.php index 38a70b32e..15a7a887d 100644 --- a/src/Appwrite/Database/Adapter/Redis.php +++ b/src/Appwrite/Database/Adapter/Redis.php @@ -42,11 +42,11 @@ class Redis extends Adapter */ public function getDocument($id) { - $output = json_decode($this->getRedis()->get($this->getNamespace().':document-'.$id), true); + $output = \json_decode($this->getRedis()->get($this->getNamespace().':document-'.$id), true); if (!$output) { $output = $this->adapter->getDocument($id); - $this->getRedis()->set($this->getNamespace().':document-'.$id, json_encode($output, JSON_UNESCAPED_UNICODE)); + $this->getRedis()->set($this->getNamespace().':document-'.$id, \json_encode($output, JSON_UNESCAPED_UNICODE)); } $output = $this->parseRelations($output); @@ -78,7 +78,7 @@ class Redis extends Adapter foreach ($output['temp-relations'] as $i => $relationship) { $node = $relationship['end']; - $node = (!empty($nodes[$i])) ? $this->parseRelations(json_decode($nodes[$i], true)) : $this->getDocument($node); + $node = (!empty($nodes[$i])) ? $this->parseRelations(\json_decode($nodes[$i], true)) : $this->getDocument($node); if (empty($node)) { continue; @@ -196,7 +196,7 @@ class Redis extends Adapter $nodes = (!empty($keys)) ? $this->getRedis()->mget($keys) : []; foreach ($data as $i => &$node) { - $temp = (!empty($nodes[$i])) ? $this->parseRelations(json_decode($nodes[$i], true)) : $this->getDocument($node); + $temp = (!empty($nodes[$i])) ? $this->parseRelations(\json_decode($nodes[$i], true)) : $this->getDocument($node); if (!empty($temp)) { $node = $temp; diff --git a/src/Appwrite/Database/Database.php b/src/Appwrite/Database/Database.php index 6540c2f25..e75eb01b5 100644 --- a/src/Appwrite/Database/Database.php +++ b/src/Appwrite/Database/Database.php @@ -122,7 +122,7 @@ class Database */ public function getCollection(array $options) { - $options = array_merge([ + $options = \array_merge([ 'offset' => 0, 'limit' => 15, 'search' => '', @@ -142,11 +142,11 @@ class Database } if ($options['first']) { - $results = reset($results); + $results = \reset($results); } if ($options['last']) { - $results = end($results); + $results = \end($results); } return $results; @@ -160,7 +160,7 @@ class Database */ public function getDocument($id, $mock = true) { - if (is_null($id)) { + if (\is_null($id)) { return new Document([]); } @@ -322,7 +322,7 @@ class Database */ public function getCount(array $options) { - $options = array_merge([ + $options = \array_merge([ 'filters' => [], ], $options); diff --git a/src/Appwrite/Database/Document.php b/src/Appwrite/Database/Document.php index ef4ee57f6..a0445702e 100644 --- a/src/Appwrite/Database/Document.php +++ b/src/Appwrite/Database/Document.php @@ -24,7 +24,7 @@ class Document extends ArrayObject public function __construct($input = null, $flags = 0, $iterator_class = 'ArrayIterator') { foreach ($input as $key => &$value) { - if (is_array($value)) { + if (\is_array($value)) { if (isset($value['$id']) || isset($value['$collection'])) { $input[$key] = new self($value); } else { @@ -76,7 +76,7 @@ class Document extends ArrayObject */ public function getAttribute($name, $default = null) { - $name = explode('.', $name); + $name = \explode('.', $name); $temp = &$this; @@ -109,12 +109,12 @@ class Document extends ArrayObject $this[$key] = $value; break; case self::SET_TYPE_APPEND: - $this[$key] = (!isset($this[$key]) || !is_array($this[$key])) ? [] : $this[$key]; - array_push($this[$key], $value); + $this[$key] = (!isset($this[$key]) || !\is_array($this[$key])) ? [] : $this[$key]; + \array_push($this[$key], $value); break; case self::SET_TYPE_PREPEND: - $this[$key] = (!isset($this[$key]) || !is_array($this[$key])) ? [] : $this[$key]; - array_unshift($this[$key], $value); + $this[$key] = (!isset($this[$key]) || !\is_array($this[$key])) ? [] : $this[$key]; + \array_unshift($this[$key], $value); break; } @@ -154,15 +154,15 @@ class Document extends ArrayObject */ public function search($key, $value, $scope = null) { - $array = (!is_null($scope)) ? $scope : $this; + $array = (!\is_null($scope)) ? $scope : $this; - if (is_array($array) || $array instanceof self) { + if (\is_array($array) || $array instanceof self) { if (isset($array[$key]) && $array[$key] == $value) { return $array; } foreach ($array as $k => $v) { - if ((is_array($v) || $v instanceof self) && (!empty($v))) { + if ((\is_array($v) || $v instanceof self) && (!empty($v))) { $result = $this->search($key, $value, $v); if (!empty($result)) { @@ -210,17 +210,17 @@ class Document extends ArrayObject $output = array(); foreach ($array as $key => &$value) { - if (!empty($whitelist) && !in_array($key, $whitelist)) { // Export only whitelisted fields + if (!empty($whitelist) && !\in_array($key, $whitelist)) { // Export only whitelisted fields continue; } - if (!empty($blacklist) && in_array($key, $blacklist)) { // Don't export blacklisted fields + if (!empty($blacklist) && \in_array($key, $blacklist)) { // Don't export blacklisted fields continue; } if ($value instanceof self) { $output[$key] = $value->getArrayCopy($whitelist, $blacklist); - } elseif (is_array($value)) { + } elseif (\is_array($value)) { foreach ($value as $childKey => &$child) { if ($child instanceof self) { $output[$key][$childKey] = $child->getArrayCopy($whitelist, $blacklist); diff --git a/src/Appwrite/Database/Validator/Authorization.php b/src/Appwrite/Database/Validator/Authorization.php index 3d556e0bd..3225251bb 100644 --- a/src/Appwrite/Database/Validator/Authorization.php +++ b/src/Appwrite/Database/Validator/Authorization.php @@ -75,14 +75,14 @@ class Authorization extends Validator $permission = null; foreach ($permissions[$this->action] as $permission) { - $permission = str_replace(':{self}', ':'.$this->document->getId(), $permission); + $permission = \str_replace(':{self}', ':'.$this->document->getId(), $permission); - if (in_array($permission, self::getRoles())) { + if (\in_array($permission, self::getRoles())) { return true; } } - $this->message = 'User is missing '.$this->action.' for "'.$permission.'" permission. Only this scopes "'.json_encode(self::getRoles()).'" is given and only this are allowed "'.json_encode($permissions[$this->action]).'".'; + $this->message = 'User is missing '.$this->action.' for "'.$permission.'" permission. Only this scopes "'.\json_encode(self::getRoles()).'" is given and only this are allowed "'.\json_encode($permissions[$this->action]).'".'; return false; } diff --git a/src/Appwrite/Database/Validator/Collection.php b/src/Appwrite/Database/Validator/Collection.php index d2a044275..5f8c81dc8 100644 --- a/src/Appwrite/Database/Validator/Collection.php +++ b/src/Appwrite/Database/Validator/Collection.php @@ -38,16 +38,16 @@ class Collection extends Structure public function isValid($document) { $document = new Document( - array_merge($this->merge, ($document instanceof Document) ? $document->getArrayCopy() : $document) + \array_merge($this->merge, ($document instanceof Document) ? $document->getArrayCopy() : $document) ); - if (is_null($document->getCollection())) { + if (\is_null($document->getCollection())) { $this->message = 'Missing collection attribute $collection'; return false; } - if (!in_array($document->getCollection(), $this->collections)) { + if (!\in_array($document->getCollection(), $this->collections)) { $this->message = 'Collection is not allowed'; return false; diff --git a/src/Appwrite/Database/Validator/Key.php b/src/Appwrite/Database/Validator/Key.php index f6cc7ce91..a71425a52 100644 --- a/src/Appwrite/Database/Validator/Key.php +++ b/src/Appwrite/Database/Validator/Key.php @@ -34,15 +34,15 @@ class Key extends Validator */ public function isValid($value) { - if(!is_string($value)) { + if(!\is_string($value)) { return false; } - if (preg_match('/[^A-Za-z0-9\-\_]/', $value)) { + if (\preg_match('/[^A-Za-z0-9\-\_]/', $value)) { return false; } - if (mb_strlen($value) > 32) { + if (\mb_strlen($value) > 32) { return false; } diff --git a/src/Appwrite/Database/Validator/Permissions.php b/src/Appwrite/Database/Validator/Permissions.php index 90144df38..553d8ff2a 100644 --- a/src/Appwrite/Database/Validator/Permissions.php +++ b/src/Appwrite/Database/Validator/Permissions.php @@ -50,21 +50,21 @@ class Permissions extends Validator */ public function isValid($value) { - if (!is_array($value) && !empty($value)) { + if (!\is_array($value) && !empty($value)) { $this->message = 'Invalid permissions data structure'; return false; } foreach ($value as $action => $roles) { - if (!in_array($action, ['read', 'write'])) { + if (!\in_array($action, ['read', 'write'])) { $this->message = 'Unknown action ("'.$action.'")'; return false; } foreach ($roles as $role) { - if (!is_string($role)) { + if (!\is_string($role)) { $this->message = 'Permissions role must be a string'; return false; diff --git a/src/Appwrite/Database/Validator/Structure.php b/src/Appwrite/Database/Validator/Structure.php index 8b807822f..3a18c4276 100644 --- a/src/Appwrite/Database/Validator/Structure.php +++ b/src/Appwrite/Database/Validator/Structure.php @@ -124,11 +124,11 @@ class Structure extends Validator */ public function isValid($document) { - $document = (is_array($document)) ? new Document($document) : $document; + $document = (\is_array($document)) ? new Document($document) : $document; $this->id = $document->getId(); - if (is_null($document->getCollection())) { + if (\is_null($document->getCollection())) { $this->message = 'Missing collection attribute $collection'; return false; @@ -136,14 +136,14 @@ class Structure extends Validator $collection = $this->getCollection($document->getCollection()); - if (is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) { + if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) { $this->message = 'Collection not found'; return false; } $array = $document->getArrayCopy(); - $rules = array_merge($this->rules, $collection->getAttribute('rules', [])); + $rules = \array_merge($this->rules, $collection->getAttribute('rules', [])); foreach ($rules as $rule) { // Check all required keys are set if (isset($rule['key']) && !isset($array[$rule['key']]) @@ -208,11 +208,11 @@ class Structure extends Validator } if (empty($validator)) { // Error creating validator for property - $this->message = 'Unknown rule type "'.$ruleType.'" for property "'.htmlspecialchars($key, ENT_QUOTES, 'UTF-8').'"'; + $this->message = 'Unknown rule type "'.$ruleType.'" for property "'.\htmlspecialchars($key, ENT_QUOTES, 'UTF-8').'"'; if (empty($ruleType)) { $this->message = 'Unknown property "'.$key.'" type'. - '. Make sure to follow '.strtolower($collection->getAttribute('name', 'unknown')).' collection structure'; + '. Make sure to follow '.\strtolower($collection->getAttribute('name', 'unknown')).' collection structure'; } return false; @@ -232,7 +232,7 @@ class Structure extends Validator } if ($ruleArray) { // Array of values validation - if (!is_array($value)) { + if (!\is_array($value)) { $this->message = 'Property "'.$key.'" must be an array'; return false; @@ -260,8 +260,8 @@ class Structure extends Validator } if (!empty($array)) { // No fields should be left unvalidated - $this->message = 'Unknown properties are not allowed ('.implode(', ', array_keys($array)).') for this collection'. - '. Make sure to follow '.strtolower($collection->getAttribute('name', 'unknown')).' collection structure'; + $this->message = 'Unknown properties are not allowed ('.\implode(', ', \array_keys($array)).') for this collection'. + '. Make sure to follow '.\strtolower($collection->getAttribute('name', 'unknown')).' collection structure'; return false; } diff --git a/src/Appwrite/Database/Validator/UID.php b/src/Appwrite/Database/Validator/UID.php index 5dc1b8d69..67a9b6c2f 100644 --- a/src/Appwrite/Database/Validator/UID.php +++ b/src/Appwrite/Database/Validator/UID.php @@ -29,7 +29,7 @@ class UID extends Validator */ public function isValid($value) { - if (is_numeric($value)) { + if (\is_numeric($value)) { //return false; } diff --git a/src/Appwrite/Network/Validator/CNAME.php b/src/Appwrite/Network/Validator/CNAME.php index fb000d22e..f9a8e5a13 100644 --- a/src/Appwrite/Network/Validator/CNAME.php +++ b/src/Appwrite/Network/Validator/CNAME.php @@ -34,12 +34,12 @@ class CNAME extends Validator public function isValid($domain) { try { - $records = dns_get_record($domain, DNS_CNAME); + $records = \dns_get_record($domain, DNS_CNAME); } catch (\Throwable $th) { return false; } - if(!$records || !is_array($records)) { + if(!$records || !\is_array($records)) { return false; } diff --git a/src/Appwrite/Network/Validator/Origin.php b/src/Appwrite/Network/Validator/Origin.php index a1c0d1f56..a0c06503a 100644 --- a/src/Appwrite/Network/Validator/Origin.php +++ b/src/Appwrite/Network/Validator/Origin.php @@ -81,7 +81,7 @@ class Origin extends Validator public function getDescription() { - if(!array_key_exists($this->client, $this->platforms)) { + if(!\array_key_exists($this->client, $this->platforms)) { return 'Unsupported platform'; } @@ -99,8 +99,8 @@ class Origin extends Validator */ public function isValid($origin) { - $scheme = parse_url($origin, PHP_URL_SCHEME); - $host = parse_url($origin, PHP_URL_HOST); + $scheme = \parse_url($origin, PHP_URL_SCHEME); + $host = \parse_url($origin, PHP_URL_HOST); $this->host = $host; $this->client = $scheme; @@ -109,7 +109,7 @@ class Origin extends Validator return true; } - if(in_array($host, $this->clients)) { + if(\in_array($host, $this->clients)) { return true; } diff --git a/src/Appwrite/OpenSSL/OpenSSL.php b/src/Appwrite/OpenSSL/OpenSSL.php index ab535076d..24d48e226 100644 --- a/src/Appwrite/OpenSSL/OpenSSL.php +++ b/src/Appwrite/OpenSSL/OpenSSL.php @@ -20,7 +20,7 @@ class OpenSSL */ public static function encrypt($data, $method, $key, $options = 0, $iv = '', &$tag = null, $aad = '', $tag_length = 16) { - return openssl_encrypt($data, $method, $key, $options, $iv, $tag, $aad, $tag_length); + return \openssl_encrypt($data, $method, $key, $options, $iv, $tag, $aad, $tag_length); } /** @@ -36,7 +36,7 @@ class OpenSSL */ public static function decrypt($data, $method, $password, $options = 1, $iv = '', $tag = '', $aad = '') { - return openssl_decrypt($data, $method, $password, $options, $iv, $tag, $aad); + return \openssl_decrypt($data, $method, $password, $options, $iv, $tag, $aad); } /** @@ -46,7 +46,7 @@ class OpenSSL */ public static function cipherIVLength($method) { - return openssl_cipher_iv_length($method); + return \openssl_cipher_iv_length($method); } /** @@ -57,6 +57,6 @@ class OpenSSL */ public static function randomPseudoBytes($length, &$crypto_strong = null) { - return openssl_random_pseudo_bytes($length, $crypto_strong); + return \openssl_random_pseudo_bytes($length, $crypto_strong); } } diff --git a/src/Appwrite/Resize/Resize.php b/src/Appwrite/Resize/Resize.php index fed3e92c9..525232e71 100644 --- a/src/Appwrite/Resize/Resize.php +++ b/src/Appwrite/Resize/Resize.php @@ -112,9 +112,9 @@ class Resize public function save(string $path = null, string $type = '', int $quality = 75) { // Create directory with write permissions - if (null !== $path && !file_exists(dirname($path))) { - if (!@mkdir(dirname($path), 0755, true)) { - throw new Exception('Can\'t create directory '.dirname($path)); + if (null !== $path && !\file_exists(\dirname($path))) { + if (!@\mkdir(\dirname($path), 0755, true)) { + throw new Exception('Can\'t create directory '.\dirname($path)); } } @@ -134,30 +134,30 @@ class Resize //$this->image->setImageFormat('webp'); $signature = $this->image->getImageSignature(); - $temp = '/tmp/temp-'.$signature.'.'.strtolower($this->image->getImageFormat()); + $temp = '/tmp/temp-'.$signature.'.'.\strtolower($this->image->getImageFormat()); $output = '/tmp/output-'.$signature.'.webp'; // save temp $this->image->writeImages($temp, true); // convert temp - exec("cwebp -quiet -metadata none -q $quality $temp -o $output"); + \exec("cwebp -quiet -metadata none -q $quality $temp -o $output"); - $data = file_get_contents($output); + $data = \file_get_contents($output); //load webp if (empty($path)) { return $data; } else { - file_put_contents($path, $data, LOCK_EX); + \file_put_contents($path, $data, LOCK_EX); } $this->image->clear(); $this->image->destroy(); //delete webp - unlink($output); - unlink($temp); + \unlink($output); + \unlink($temp); return; @@ -165,7 +165,7 @@ class Resize case 'png': /* Scale quality from 0-100 to 0-9 */ - $scaleQuality = round(($quality / 100) * 9); + $scaleQuality = \round(($quality / 100) * 9); /* Invert quality setting as 0 is best, not 9 */ $invertScaleQuality = 9 - $scaleQuality; diff --git a/src/Appwrite/Storage/Compression/Algorithms/GZIP.php b/src/Appwrite/Storage/Compression/Algorithms/GZIP.php index 61a6ccc8f..df4e0236b 100644 --- a/src/Appwrite/Storage/Compression/Algorithms/GZIP.php +++ b/src/Appwrite/Storage/Compression/Algorithms/GZIP.php @@ -28,7 +28,7 @@ class GZIP extends Compression */ public function compress(string $data):string { - return gzencode($data); + return \gzencode($data); } /** @@ -40,6 +40,6 @@ class GZIP extends Compression */ public function decompress(string $data):string { - return gzdecode($data); + return \gzdecode($data); } } diff --git a/src/Appwrite/Storage/Device/Local.php b/src/Appwrite/Storage/Device/Local.php index 9a331529b..961daee38 100644 --- a/src/Appwrite/Storage/Device/Local.php +++ b/src/Appwrite/Storage/Device/Local.php @@ -56,7 +56,7 @@ class Local extends Device $path = ''; for ($i = 0; $i < 4; ++$i) { - $path = ($i < strlen($filename)) ? $path.DIRECTORY_SEPARATOR.$filename[$i] : $path.DIRECTORY_SEPARATOR.'x'; + $path = ($i < \strlen($filename)) ? $path.DIRECTORY_SEPARATOR.$filename[$i] : $path.DIRECTORY_SEPARATOR.'x'; } return $this->getRoot().$path.DIRECTORY_SEPARATOR.$filename; @@ -76,13 +76,13 @@ class Local extends Device */ public function upload($source, $path):bool { - if (!file_exists(dirname($path))) { // Checks if directory path to file exists - if (!@mkdir(dirname($path), 0755, true)) { - throw new Exception('Can\'t create directory: '.dirname($path)); + if (!\file_exists(\dirname($path))) { // Checks if directory path to file exists + if (!@\mkdir(\dirname($path), 0755, true)) { + throw new Exception('Can\'t create directory: '.\dirname($path)); } } - if (move_uploaded_file($source, $path)) { + if (\move_uploaded_file($source, $path)) { return true; } @@ -98,7 +98,7 @@ class Local extends Device */ public function read(string $path):string { - return file_get_contents($path); + return \file_get_contents($path); } /** @@ -111,13 +111,13 @@ class Local extends Device */ public function write(string $path, string $data):bool { - if (!file_exists(dirname($path))) { // Checks if directory path to file exists - if (!@mkdir(dirname($path), 0755, true)) { - throw new Exception('Can\'t create directory '.dirname($path)); + if (!\file_exists(\dirname($path))) { // Checks if directory path to file exists + if (!@\mkdir(\dirname($path), 0755, true)) { + throw new Exception('Can\'t create directory '.\dirname($path)); } } - return file_put_contents($path, $data); + return \file_put_contents($path, $data); } /** @@ -132,13 +132,13 @@ class Local extends Device */ public function move(string $source, string $target):bool { - if (!file_exists(dirname($target))) { // Checks if directory path to file exists - if (!@mkdir(dirname($target), 0755, true)) { - throw new Exception('Can\'t create directory '.dirname($target)); + if (!\file_exists(\dirname($target))) { // Checks if directory path to file exists + if (!@\mkdir(\dirname($target), 0755, true)) { + throw new Exception('Can\'t create directory '.\dirname($target)); } } - if (rename($source, $target)) { + if (\rename($source, $target)) { return true; } @@ -157,17 +157,17 @@ class Local extends Device */ public function delete(string $path, bool $recursive = false):bool { - if(is_dir($path) && $recursive) { - $files = glob($path.'*', GLOB_MARK); // GLOB_MARK adds a slash to directories returned + if(\is_dir($path) && $recursive) { + $files = \glob($path.'*', GLOB_MARK); // GLOB_MARK adds a slash to directories returned foreach($files as $file) { $this->delete($file, true); } - rmdir($path); + \rmdir($path); } - elseif(is_file($path)) { - return unlink($path); + elseif(\is_file($path)) { + return \unlink($path); } return false; @@ -184,7 +184,7 @@ class Local extends Device */ public function getFileSize(string $path):int { - return filesize($path); + return \filesize($path); } /** @@ -198,7 +198,7 @@ class Local extends Device */ public function getFileMimeType(string $path):string { - return mime_content_type($path); + return \mime_content_type($path); } /** @@ -212,7 +212,7 @@ class Local extends Device */ public function getFileHash(string $path):string { - return md5_file($path); + return \md5_file($path); } /** @@ -230,27 +230,27 @@ class Local extends Device { $size = 0; - $directory = opendir($path); + $directory = \opendir($path); if (!$directory) { return -1; } - while (($file = readdir($directory)) !== false) { + while (($file = \readdir($directory)) !== false) { // Skip file pointers if ($file[0] == '.') { continue; } // Go recursive down, or add the file size - if (is_dir($path.$file)) { + if (\is_dir($path.$file)) { $size += $this->getDirectorySize($path.$file.DIRECTORY_SEPARATOR); } else { - $size += filesize($path.$file); + $size += \filesize($path.$file); } } - closedir($directory); + \closedir($directory); return $size; } @@ -264,7 +264,7 @@ class Local extends Device */ public function getPartitionFreeSpace():float { - return disk_free_space($this->getRoot()); + return \disk_free_space($this->getRoot()); } /** @@ -276,6 +276,6 @@ class Local extends Device */ public function getPartitionTotalSpace():float { - return disk_total_space($this->getRoot()); + return \disk_total_space($this->getRoot()); } } diff --git a/src/Appwrite/Storage/Device/S3.php b/src/Appwrite/Storage/Device/S3.php index 5706891b2..5270c14d9 100644 --- a/src/Appwrite/Storage/Device/S3.php +++ b/src/Appwrite/Storage/Device/S3.php @@ -40,7 +40,7 @@ class S3 extends Device $path = ''; for ($i = 0; $i < 4; ++$i) { - $path = ($i < strlen($filename)) ? $path.DIRECTORY_SEPARATOR.$filename[$i] : $path.DIRECTORY_SEPARATOR.'x'; + $path = ($i < \strlen($filename)) ? $path.DIRECTORY_SEPARATOR.$filename[$i] : $path.DIRECTORY_SEPARATOR.'x'; } return $this->getRoot().$path.DIRECTORY_SEPARATOR.$filename; diff --git a/src/Appwrite/Storage/Storage.php b/src/Appwrite/Storage/Storage.php index a5d38e0f5..800c90b43 100644 --- a/src/Appwrite/Storage/Storage.php +++ b/src/Appwrite/Storage/Storage.php @@ -27,7 +27,7 @@ class Storage */ public static function addDevice($name, Device $device) { - if (array_key_exists($name, self::$devices)) { + if (\array_key_exists($name, self::$devices)) { throw new Exception('The device "'.$name.'" is already listed'); } @@ -47,7 +47,7 @@ class Storage */ public static function getDevice($name) { - if (!array_key_exists($name, self::$devices)) { + if (!\array_key_exists($name, self::$devices)) { throw new Exception('The device "'.$name.'" is not listed'); } @@ -65,7 +65,7 @@ class Storage */ public static function exists($name) { - return (bool) array_key_exists($name, self::$devices); + return (bool) \array_key_exists($name, self::$devices); } /** @@ -89,6 +89,6 @@ class Storage ++$i; } - return round($bytes, $decimals).$units[$i]; + return \round($bytes, $decimals).$units[$i]; } } diff --git a/src/Appwrite/Storage/Validator/FileName.php b/src/Appwrite/Storage/Validator/FileName.php index d823e9ba5..728e46552 100644 --- a/src/Appwrite/Storage/Validator/FileName.php +++ b/src/Appwrite/Storage/Validator/FileName.php @@ -24,7 +24,7 @@ class FileName extends Validator return false; } - if (!preg_match('/^[a-zA-Z0-9.]+$/', $name)) { + if (!\preg_match('/^[a-zA-Z0-9.]+$/', $name)) { return false; } diff --git a/src/Appwrite/Storage/Validator/FileType.php b/src/Appwrite/Storage/Validator/FileType.php index 7ceceb48f..c66631e73 100644 --- a/src/Appwrite/Storage/Validator/FileType.php +++ b/src/Appwrite/Storage/Validator/FileType.php @@ -68,23 +68,23 @@ class FileType extends Validator return false; } - $handle = fopen($path, 'r'); + $handle = \fopen($path, 'r'); if (!$handle) { return false; } - $bytes = fgets($handle, 8); + $bytes = \fgets($handle, 8); foreach ($this->whiteList as $key) { - if (strpos($bytes, $this->types[$key]) === 0) { - fclose($handle); + if (\strpos($bytes, $this->types[$key]) === 0) { + \fclose($handle); return true; } } - fclose($handle); + \fclose($handle); return false; } diff --git a/src/Appwrite/Template/Template.php b/src/Appwrite/Template/Template.php index 18dfecd51..127afef15 100644 --- a/src/Appwrite/Template/Template.php +++ b/src/Appwrite/Template/Template.php @@ -23,13 +23,13 @@ class Template extends View return ''; } - if (is_readable($this->path)) { - $template = file_get_contents($this->path); // Include template file + if (\is_readable($this->path)) { + $template = \file_get_contents($this->path); // Include template file } else { throw new Exception('"'.$this->path.'" template is not readable or not found'); } - $template = str_replace(array_keys($this->params), array_values($this->params), $template); + $template = \str_replace(\array_keys($this->params), \array_values($this->params), $template); return $template; } @@ -45,7 +45,7 @@ class Template extends View */ public static function parseURL($url) { - return parse_url($url); + return \parse_url($url); } /** @@ -89,10 +89,10 @@ class Template extends View { $parsed = []; - parse_str($query1, $parsed); + \parse_str($query1, $parsed); - $parsed = array_merge($parsed, $query2); + $parsed = \array_merge($parsed, $query2); - return http_build_query($parsed); + return \http_build_query($parsed); } } diff --git a/src/Appwrite/URL/URL.php b/src/Appwrite/URL/URL.php index e49845c53..b4e55039e 100644 --- a/src/Appwrite/URL/URL.php +++ b/src/Appwrite/URL/URL.php @@ -26,7 +26,7 @@ class URL 'fragment' => '', ]; - return array_merge($default, parse_url($url)); + return \array_merge($default, \parse_url($url)); } /** @@ -41,7 +41,7 @@ class URL */ static public function unparse(array $url, array $ommit = []):string { - if (isset($url['path']) && mb_substr($url['path'], 0, 1) !== '/') { + if (isset($url['path']) && \mb_substr($url['path'], 0, 1) !== '/') { $url['path'] = '/'.$url['path']; } @@ -87,7 +87,7 @@ class URL */ static public function parseQuery(string $query):array { - parse_str($query, $result); + \parse_str($query, $result); return $result; } @@ -103,6 +103,6 @@ class URL */ static public function unparseQuery(array $query):string { - return http_build_query($query); + return \http_build_query($query); } } \ No newline at end of file