From 6392ceef55ce6d7cd403755b96dce64cd35a6de0 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Tue, 27 Oct 2020 21:44:15 +0200 Subject: [PATCH] Updated src folder --- src/Appwrite/Auth/OAuth2/Box.php | 11 +++++++++-- src/Appwrite/Auth/OAuth2/Github.php | 2 +- src/Appwrite/Database/Adapter/MySQL.php | 2 +- src/Appwrite/Database/Database.php | 8 ++++---- src/Appwrite/Database/Validator/Structure.php | 2 +- src/Appwrite/Database/Validator/UID.php | 2 +- src/Appwrite/Docker/Compose.php | 2 +- src/Appwrite/Docker/Env.php | 5 ++--- src/Appwrite/Extend/PDOStatement.php | 6 +++--- src/Appwrite/Network/Validator/CNAME.php | 2 +- src/Appwrite/Network/Validator/Domain.php | 4 ++-- src/Appwrite/Network/Validator/Origin.php | 2 +- src/Appwrite/Storage/Validator/FileName.php | 2 +- src/Appwrite/Storage/Validator/FileSize.php | 2 +- src/Appwrite/Storage/Validator/Upload.php | 2 +- src/Appwrite/Swoole/Files.php | 14 +++++++------- src/Appwrite/Swoole/Request.php | 8 ++++---- src/Appwrite/Swoole/Response.php | 9 ++++----- src/Appwrite/Task/Validator/Cron.php | 2 +- src/Appwrite/Utopia/Response.php | 19 +++++++++---------- src/Appwrite/Utopia/Response/Model/File.php | 1 - 21 files changed, 55 insertions(+), 52 deletions(-) diff --git a/src/Appwrite/Auth/OAuth2/Box.php b/src/Appwrite/Auth/OAuth2/Box.php index 48e2a387a..7fbcf5954 100644 --- a/src/Appwrite/Auth/OAuth2/Box.php +++ b/src/Appwrite/Auth/OAuth2/Box.php @@ -9,9 +9,14 @@ use Appwrite\Auth\OAuth2; class Box extends OAuth2 { - + /** + * @var string + */ private $endpoint = 'https://account.box.com/api/oauth2/'; + /** + * @var string + */ private $resourceEndpoint = 'https://api.box.com/2.0/'; /** @@ -19,6 +24,9 @@ class Box extends OAuth2 */ protected $user = []; + /** + * @var array + */ protected $scopes = [ 'manage_app_users', ]; @@ -148,5 +156,4 @@ class Box extends OAuth2 return $this->user; } - } \ No newline at end of file diff --git a/src/Appwrite/Auth/OAuth2/Github.php b/src/Appwrite/Auth/OAuth2/Github.php index 3ab8e51a8..0f86b8910 100644 --- a/src/Appwrite/Auth/OAuth2/Github.php +++ b/src/Appwrite/Auth/OAuth2/Github.php @@ -125,7 +125,7 @@ class Github extends OAuth2 * @return array */ 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); } diff --git a/src/Appwrite/Database/Adapter/MySQL.php b/src/Appwrite/Database/Adapter/MySQL.php index d361433df..b61e473c4 100644 --- a/src/Appwrite/Database/Adapter/MySQL.php +++ b/src/Appwrite/Database/Adapter/MySQL.php @@ -232,7 +232,7 @@ class MySQL extends Adapter // Handle array of relations if (self::DATA_TYPE_ARRAY === $type) { - if(!is_array($value)) { // Property should be of type array, if not = skip + if (!is_array($value)) { // Property should be of type array, if not = skip continue; } diff --git a/src/Appwrite/Database/Database.php b/src/Appwrite/Database/Database.php index 70725a89d..c0d8deb84 100644 --- a/src/Appwrite/Database/Database.php +++ b/src/Appwrite/Database/Database.php @@ -452,7 +452,7 @@ class Database $filters = $rule->getAttribute('filter', null); $value = $document->getAttribute($key, null); - if(($value !== null) && is_array($filters)) { + if (($value !== null) && is_array($filters)) { foreach ($filters as $filter) { $value = $this->encodeAttribute($filter, $value); $document->setAttribute($key, $value); @@ -473,7 +473,7 @@ class Database $filters = $rule->getAttribute('filter', null); $value = $document->getAttribute($key, null); - if(($value !== null) && is_array($filters)) { + if (($value !== null) && is_array($filters)) { foreach (array_reverse($filters) as $filter) { $value = $this->decodeAttribute($filter, $value); $document->setAttribute($key, $value); @@ -492,7 +492,7 @@ class Database */ static protected function encodeAttribute(string $name, $value) { - if(!isset(self::$filters[$name])) { + if (!isset(self::$filters[$name])) { throw new Exception('Filter not found'); } @@ -513,7 +513,7 @@ class Database */ static protected function decodeAttribute(string $name, $value) { - if(!isset(self::$filters[$name])) { + if (!isset(self::$filters[$name])) { throw new Exception('Filter not found'); } diff --git a/src/Appwrite/Database/Validator/Structure.php b/src/Appwrite/Database/Validator/Structure.php index 34d885039..5aea6c1b3 100644 --- a/src/Appwrite/Database/Validator/Structure.php +++ b/src/Appwrite/Database/Validator/Structure.php @@ -157,7 +157,7 @@ class Structure extends Validator foreach ($array as $key => $value) { $rule = $collection->search('key', $key, $rules); - if(!$rule) { + if (!$rule) { continue; } diff --git a/src/Appwrite/Database/Validator/UID.php b/src/Appwrite/Database/Validator/UID.php index a68c3da35..4cc3f1d5b 100644 --- a/src/Appwrite/Database/Validator/UID.php +++ b/src/Appwrite/Database/Validator/UID.php @@ -37,7 +37,7 @@ class UID extends Validator return false; } - if(mb_strlen($value) > 32) { + if (mb_strlen($value) > 32) { return false; } diff --git a/src/Appwrite/Docker/Compose.php b/src/Appwrite/Docker/Compose.php index e9fb90687..e5c6a8171 100644 --- a/src/Appwrite/Docker/Compose.php +++ b/src/Appwrite/Docker/Compose.php @@ -48,7 +48,7 @@ class Compose */ public function getService(string $name): Service { - if(!isset($this->compose['services'][$name])) { + if (!isset($this->compose['services'][$name])) { throw new Exception('Service not found'); } diff --git a/src/Appwrite/Docker/Env.php b/src/Appwrite/Docker/Env.php index f97f68b00..3076eb643 100644 --- a/src/Appwrite/Docker/Env.php +++ b/src/Appwrite/Docker/Env.php @@ -16,15 +16,14 @@ class Env */ public function __construct(string $data) { - $data = explode("\n", $data); - foreach($data as &$row) { + foreach ($data as &$row) { $row = explode('=', $row); $key = (isset($row[0])) ? trim($row[0]) : null; $value = (isset($row[1])) ? trim($row[1]) : null; - if($key) { + if ($key) { $this->vars[$key] = $value; } } diff --git a/src/Appwrite/Extend/PDOStatement.php b/src/Appwrite/Extend/PDOStatement.php index a752f9f27..412607d9e 100644 --- a/src/Appwrite/Extend/PDOStatement.php +++ b/src/Appwrite/Extend/PDOStatement.php @@ -73,15 +73,15 @@ class PDOStatement extends PDOStatementNative $this->pdo = $this->pdo->reconnect(); $this->PDOStatement = $this->pdo->prepare($this->PDOStatement->queryString, []); - foreach($this->values as $key => $set) { + foreach ($this->values as $key => $set) { $this->PDOStatement->bindValue($key, $set['value'], $set['data_type']); } - foreach($this->params as $key => $set) { + foreach ($this->params as $key => $set) { $this->PDOStatement->bindParam($key, $set['variable'], $set['data_type'], $set['length'], $set['driver_options']); } - foreach($this->columns as $key => $set) { + foreach ($this->columns as $key => $set) { $this->PDOStatement->bindColumn($key, $set['param'], $set['type'], $set['maxlen'], $set['driverdata']); } diff --git a/src/Appwrite/Network/Validator/CNAME.php b/src/Appwrite/Network/Validator/CNAME.php index 1d299e48c..c2adfdddd 100644 --- a/src/Appwrite/Network/Validator/CNAME.php +++ b/src/Appwrite/Network/Validator/CNAME.php @@ -36,7 +36,7 @@ class CNAME extends Validator */ public function isValid($domain) { - if(!is_string($domain)) { + if (!is_string($domain)) { return false; } diff --git a/src/Appwrite/Network/Validator/Domain.php b/src/Appwrite/Network/Validator/Domain.php index 848e338d6..0d5def06c 100644 --- a/src/Appwrite/Network/Validator/Domain.php +++ b/src/Appwrite/Network/Validator/Domain.php @@ -37,11 +37,11 @@ class Domain extends Validator */ public function isValid($value) { - if(empty($value)) { + if (empty($value)) { return false; } - if(!is_string($value)) { + if (!is_string($value)) { return false; } diff --git a/src/Appwrite/Network/Validator/Origin.php b/src/Appwrite/Network/Validator/Origin.php index 62f1608af..c0afb1f56 100644 --- a/src/Appwrite/Network/Validator/Origin.php +++ b/src/Appwrite/Network/Validator/Origin.php @@ -99,7 +99,7 @@ class Origin extends Validator */ public function isValid($origin) { - if(!is_string($origin)) { + if (!is_string($origin)) { return false; } diff --git a/src/Appwrite/Storage/Validator/FileName.php b/src/Appwrite/Storage/Validator/FileName.php index a7d2e43a7..acb76fdab 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(!is_string($name)) { + if (!is_string($name)) { return false; } diff --git a/src/Appwrite/Storage/Validator/FileSize.php b/src/Appwrite/Storage/Validator/FileSize.php index ab5d36144..1bbf74918 100644 --- a/src/Appwrite/Storage/Validator/FileSize.php +++ b/src/Appwrite/Storage/Validator/FileSize.php @@ -35,7 +35,7 @@ class FileSize extends Validator */ public function isValid($fileSize) { - if(!is_int($fileSize)) { + if (!is_int($fileSize)) { return false; } diff --git a/src/Appwrite/Storage/Validator/Upload.php b/src/Appwrite/Storage/Validator/Upload.php index 023946442..38296e8d0 100644 --- a/src/Appwrite/Storage/Validator/Upload.php +++ b/src/Appwrite/Storage/Validator/Upload.php @@ -20,7 +20,7 @@ class Upload extends Validator */ public function isValid($path) { - if(!is_string($path)) { + if (!is_string($path)) { return false; } diff --git a/src/Appwrite/Swoole/Files.php b/src/Appwrite/Swoole/Files.php index 7971beba2..8c8e52ea3 100644 --- a/src/Appwrite/Swoole/Files.php +++ b/src/Appwrite/Swoole/Files.php @@ -51,7 +51,7 @@ class Files */ public static function removeMimeType(string $mimeType): void { - if(isset(self::$mimeTypes[$mimeType])) { + if (isset(self::$mimeTypes[$mimeType])) { unset(self::$mimeTypes[$mimeType]); } } @@ -85,7 +85,7 @@ class Files */ public static function load(string $directory, string $root = null): void { - if(!is_readable($directory)) { + if (!is_readable($directory)) { throw new Exception('Failed to load directory: '.$directory); } @@ -106,7 +106,7 @@ class Files continue; } - if(substr($path, 0, 1) === '.') { + if (substr($path, 0, 1) === '.') { continue; } @@ -127,7 +127,7 @@ class Files closedir($handle); - if($directory === $root) { + if ($directory === $root) { echo '[Static Files] Loadded '.self::$count.' files'.PHP_EOL; } } @@ -139,7 +139,7 @@ class Files */ public static function isFileLoaded(string $uri): bool { - if(!array_key_exists($uri, self::$loaded)) { + if (!array_key_exists($uri, self::$loaded)) { return false; } @@ -153,7 +153,7 @@ class Files */ public static function getFileContents(string $uri): string { - if(!array_key_exists($uri, self::$loaded)) { + if (!array_key_exists($uri, self::$loaded)) { throw new Exception('File not found or not loaded: '.$uri); } @@ -167,7 +167,7 @@ class Files */ public static function getFileMimeType(string $uri): string { - if(!array_key_exists($uri, self::$loaded)) { + if (!array_key_exists($uri, self::$loaded)) { throw new Exception('File not found or not loaded: '.$uri); } diff --git a/src/Appwrite/Swoole/Request.php b/src/Appwrite/Swoole/Request.php index 453592468..d3b04809e 100644 --- a/src/Appwrite/Swoole/Request.php +++ b/src/Appwrite/Swoole/Request.php @@ -33,7 +33,7 @@ class Request extends UtopiaRequest */ public function getParam(string $key, $default = null) { - switch($this->getMethod()) { + switch ($this->getMethod()) { case self::METHOD_GET: return $this->getQuery($key, $default); break; @@ -57,7 +57,7 @@ class Request extends UtopiaRequest */ public function getParams(): array { - switch($this->getMethod()) { + switch ($this->getMethod()) { case self::METHOD_GET: return (!empty($this->swoole->get)) ? $this->swoole->get : []; break; @@ -143,7 +143,7 @@ class Request extends UtopiaRequest { $protocol = $this->getHeader('x-forwarded-proto', $this->getServer('server_protocol', 'https')); - if($protocol === 'HTTP/1.1') { + if ($protocol === 'HTTP/1.1') { return 'http'; } @@ -317,7 +317,7 @@ class Request extends UtopiaRequest break; } - if(empty($this->payload)) { // Make sure we return same data type even if json payload is empty or failed + if (empty($this->payload)) { // Make sure we return same data type even if json payload is empty or failed $this->payload = []; } } diff --git a/src/Appwrite/Swoole/Response.php b/src/Appwrite/Swoole/Response.php index 766101146..98f481ee8 100644 --- a/src/Appwrite/Swoole/Response.php +++ b/src/Appwrite/Swoole/Response.php @@ -37,7 +37,7 @@ class Response extends UtopiaResponse * Response constructor. */ public function __construct(SwooleResponse $response) - { + { $this->swoole = $response; parent::__construct(\microtime(true)); } @@ -54,7 +54,7 @@ class Response extends UtopiaResponse */ public function send(string $body = '', int $exit = null): void { - if(!$this->disablePayload) { + if (!$this->disablePayload) { $this->addHeader('X-Debug-Speed', (string)(microtime(true) - $this->startTime)); $this @@ -67,13 +67,12 @@ class Response extends UtopiaResponse $this->size = $this->size + strlen(implode("\n", $this->headers)) + $length; - if(array_key_exists( + if (array_key_exists( $this->contentType, $this->compressed ) && ($length <= $chunk)) { // Dont compress with GZIP / Brotli if header is not listed and size is bigger than 2mb $this->swoole->end($body); - } - else { + } else { for ($i=0; $i < ceil($length / $chunk); $i++) { $this->swoole->write(substr($body, ($i * $chunk), min((($i * $chunk) + $chunk), $length))); } diff --git a/src/Appwrite/Task/Validator/Cron.php b/src/Appwrite/Task/Validator/Cron.php index 68c7c4b0f..18f427ee7 100644 --- a/src/Appwrite/Task/Validator/Cron.php +++ b/src/Appwrite/Task/Validator/Cron.php @@ -30,7 +30,7 @@ class Cron extends Validator */ public function isValid($value) { - if(empty($value)) { + if (empty($value)) { return true; } diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index b2a9f5b5d..2bcf979c3 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -101,7 +101,7 @@ class Response extends UtopiaResponse */ public function getModel(string $key): Model { - if(!isset($this->models[$key])) { + if (!isset($this->models[$key])) { throw new Exception('Undefined model: '.$key); } @@ -126,23 +126,22 @@ class Response extends UtopiaResponse $model = $this->getModel($model); $output = []; - foreach($model->getRules() as $key => $rule) { - if(!$document->isSet($key)) { - if(!is_null($rule['default'])) { + foreach ($model->getRules() as $key => $rule) { + if (!$document->isSet($key)) { + if (!is_null($rule['default'])) { $document->setAttribute($key, $rule['default']); - } - else { + } else { throw new Exception('Missing response key: '.$key); } } - if($rule['array']) { - if(!is_array($data[$key])) { + if ($rule['array']) { + if (!is_array($data[$key])) { throw new Exception($key.' must be an array of '.$rule['type'].' types'); } foreach ($data[$key] as &$item) { - if(array_key_exists($rule['type'], $this->models) && $item instanceof Document) { + if (array_key_exists($rule['type'], $this->models) && $item instanceof Document) { $item = $this->output($item, $rule['type']); } } @@ -168,7 +167,7 @@ class Response extends UtopiaResponse */ public function yaml(array $data): void { - if(!extension_loaded('yaml')) { + if (!extension_loaded('yaml')) { throw new Exception('Missing yaml extension. Learn more at: https://www.php.net/manual/en/book.yaml.php'); } diff --git a/src/Appwrite/Utopia/Response/Model/File.php b/src/Appwrite/Utopia/Response/Model/File.php index 875c6f4bd..2b48e0411 100644 --- a/src/Appwrite/Utopia/Response/Model/File.php +++ b/src/Appwrite/Utopia/Response/Model/File.php @@ -9,7 +9,6 @@ class File extends Model { public function __construct() { - } /**