From dcf4e948e743f286863962f1122b3025276ef29c Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 25 Jun 2020 00:02:27 +0300 Subject: [PATCH] Fixed coding standards --- src/Appwrite/Auth/OAuth2.php | 12 ++++++------ src/Appwrite/Auth/OAuth2/Apple.php | 7 ++++--- src/Appwrite/Auth/OAuth2/GitHub.php | 1 - src/Appwrite/Auth/OAuth2/Slack.php | 1 - src/Appwrite/Database/Adapter/MySQL.php | 6 +++--- src/Appwrite/Database/Document.php | 2 +- src/Appwrite/Database/Validator/Authorization.php | 3 ++- src/Appwrite/Database/Validator/DocumentId.php | 8 ++++---- src/Appwrite/Database/Validator/Key.php | 2 +- src/Appwrite/Network/Validator/CNAME.php | 6 +++--- src/Appwrite/Network/Validator/Origin.php | 8 ++++---- src/Appwrite/Storage/Device/Local.php | 9 ++++----- src/Appwrite/Storage/Validator/FileType.php | 2 +- 13 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/Appwrite/Auth/OAuth2.php b/src/Appwrite/Auth/OAuth2.php index 8547edc758..14c6c94a4a 100644 --- a/src/Appwrite/Auth/OAuth2.php +++ b/src/Appwrite/Auth/OAuth2.php @@ -44,7 +44,7 @@ abstract class OAuth2 $this->appSecret = $appSecret; $this->callback = $callback; $this->state = $state; - foreach($scopes as $scope) { + foreach ($scopes as $scope) { $this->addScope($scope); } } @@ -95,15 +95,15 @@ 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)){ - $this->scopes[] = $scope; + if (!\in_array($scope, $this->scopes)) { + $this->scopes[] = $scope; } return $this; } - /** - * @return array - */ + /** + * @return array + */ protected function getScopes():array { return $this->scopes; diff --git a/src/Appwrite/Auth/OAuth2/Apple.php b/src/Appwrite/Auth/OAuth2/Apple.php index 9fdf2ab222..097cbea936 100644 --- a/src/Appwrite/Auth/OAuth2/Apple.php +++ b/src/Appwrite/Auth/OAuth2/Apple.php @@ -166,7 +166,9 @@ class Apple extends OAuth2 $success = \openssl_sign($payload, $signature, $pkey, OPENSSL_ALGO_SHA256); - if (!$success) return ''; + if (!$success) { + return ''; + } return $payload.'.'.$this->encode($this->fromDER($signature, 64)); } @@ -205,8 +207,7 @@ class Apple extends OAuth2 if ('81' === \mb_substr($hex, 2, 2, '8bit')) { // LENGTH > 128 $hex = \mb_substr($hex, 6, null, '8bit'); - } - else { + } else { $hex = \mb_substr($hex, 4, null, '8bit'); } if ('02' !== \mb_substr($hex, 0, 2, '8bit')) { // INTEGER diff --git a/src/Appwrite/Auth/OAuth2/GitHub.php b/src/Appwrite/Auth/OAuth2/GitHub.php index 9f571da3a5..882f2d3f2a 100644 --- a/src/Appwrite/Auth/OAuth2/GitHub.php +++ b/src/Appwrite/Auth/OAuth2/GitHub.php @@ -37,7 +37,6 @@ class Github extends OAuth2 'scope' => \implode(' ', $this->getScopes()), 'state' => \json_encode($this->state) ]); - } /** diff --git a/src/Appwrite/Auth/OAuth2/Slack.php b/src/Appwrite/Auth/OAuth2/Slack.php index 6848046868..c5d8f7c53b 100644 --- a/src/Appwrite/Auth/OAuth2/Slack.php +++ b/src/Appwrite/Auth/OAuth2/Slack.php @@ -125,7 +125,6 @@ class Slack extends OAuth2 */ protected function getUser(string $accessToken):array { - if (empty($this->user)) { // https://api.slack.com/methods/users.identity $user = $this->request( diff --git a/src/Appwrite/Database/Adapter/MySQL.php b/src/Appwrite/Database/Adapter/MySQL.php index 461d2a29ef..f766666306 100644 --- a/src/Appwrite/Database/Adapter/MySQL.php +++ b/src/Appwrite/Database/Adapter/MySQL.php @@ -175,7 +175,7 @@ class MySQL extends Adapter $result = $st->fetch(); - if($result && isset($result['signature'])) { + if ($result && isset($result['signature'])) { $oldSignature = $result['signature']; if ($signature === $oldSignature) { @@ -187,14 +187,14 @@ class MySQL extends Adapter /** * Check Unique Keys */ - foreach($unique as $key => $value) { + foreach ($unique as $key => $value) { $st = $this->getPDO()->prepare('INSERT INTO `'.$this->getNamespace().'.database.unique` SET `key` = :key; '); $st->bindValue(':key', \md5($data['$collection'].':'.$key.'='.$value), PDO::PARAM_STR); - if(!$st->execute()) { + if (!$st->execute()) { throw new Duplicate('Duplicated Property: '.$key.'='.$value); } } diff --git a/src/Appwrite/Database/Document.php b/src/Appwrite/Database/Document.php index a0445702e4..bd085c2fa5 100644 --- a/src/Appwrite/Database/Document.php +++ b/src/Appwrite/Database/Document.php @@ -134,7 +134,7 @@ class Document extends ArrayObject */ public function removeAttribute($key) { - if(isset($this[$key])) { + if (isset($this[$key])) { unset($this[$key]); } diff --git a/src/Appwrite/Database/Validator/Authorization.php b/src/Appwrite/Database/Validator/Authorization.php index 3225251bb7..fdadd05109 100644 --- a/src/Appwrite/Database/Validator/Authorization.php +++ b/src/Appwrite/Database/Validator/Authorization.php @@ -121,7 +121,8 @@ class Authorization extends Validator * This will be used for the * value set on the self::reset() method */ - public static function setDefaultStatus($status) { + public static function setDefaultStatus($status) + { self::$statusDefault = $status; self::$status = $status; } diff --git a/src/Appwrite/Database/Validator/DocumentId.php b/src/Appwrite/Database/Validator/DocumentId.php index 0c89e88651..56041dc34b 100644 --- a/src/Appwrite/Database/Validator/DocumentId.php +++ b/src/Appwrite/Database/Validator/DocumentId.php @@ -60,19 +60,19 @@ class DocumentId extends Validator { $document = $this->database->getDocument($id); - if(!$document) { + if (!$document) { return false; } - if(!$document instanceof Document) { + if (!$document instanceof Document) { return false; } - if(!$document->getId()) { + if (!$document->getId()) { return false; } - if($document->getCollection() !== $this->collection) { + if ($document->getCollection() !== $this->collection) { return false; } diff --git a/src/Appwrite/Database/Validator/Key.php b/src/Appwrite/Database/Validator/Key.php index a71425a52a..53cdc3eb77 100644 --- a/src/Appwrite/Database/Validator/Key.php +++ b/src/Appwrite/Database/Validator/Key.php @@ -34,7 +34,7 @@ class Key extends Validator */ public function isValid($value) { - if(!\is_string($value)) { + if (!\is_string($value)) { return false; } diff --git a/src/Appwrite/Network/Validator/CNAME.php b/src/Appwrite/Network/Validator/CNAME.php index f9a8e5a13f..708396e81c 100644 --- a/src/Appwrite/Network/Validator/CNAME.php +++ b/src/Appwrite/Network/Validator/CNAME.php @@ -39,12 +39,12 @@ class CNAME extends Validator return false; } - if(!$records || !\is_array($records)) { + if (!$records || !\is_array($records)) { return false; } - foreach($records as $record) { - if(isset($record['target']) && $record['target'] === $this->target) { + foreach ($records as $record) { + if (isset($record['target']) && $record['target'] === $this->target) { return true; } } diff --git a/src/Appwrite/Network/Validator/Origin.php b/src/Appwrite/Network/Validator/Origin.php index a0c06503af..eb838367e1 100644 --- a/src/Appwrite/Network/Validator/Origin.php +++ b/src/Appwrite/Network/Validator/Origin.php @@ -56,7 +56,7 @@ class Origin extends Validator */ public function __construct($platforms) { - foreach($platforms as $platform) { + foreach ($platforms as $platform) { $type = (isset($platform['type'])) ? $platform['type'] : ''; switch ($type) { @@ -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'; } @@ -105,11 +105,11 @@ class Origin extends Validator $this->host = $host; $this->client = $scheme; - if(empty($host)) { + if (empty($host)) { return true; } - if(\in_array($host, $this->clients)) { + if (\in_array($host, $this->clients)) { return true; } diff --git a/src/Appwrite/Storage/Device/Local.php b/src/Appwrite/Storage/Device/Local.php index 961daee38e..d786e2b076 100644 --- a/src/Appwrite/Storage/Device/Local.php +++ b/src/Appwrite/Storage/Device/Local.php @@ -157,16 +157,15 @@ class Local extends Device */ public function delete(string $path, bool $recursive = false):bool { - if(\is_dir($path) && $recursive) { + 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); + foreach ($files as $file) { + $this->delete($file, true); } \rmdir($path); - } - elseif(\is_file($path)) { + } elseif (\is_file($path)) { return \unlink($path); } diff --git a/src/Appwrite/Storage/Validator/FileType.php b/src/Appwrite/Storage/Validator/FileType.php index c66631e73b..164e59924b 100644 --- a/src/Appwrite/Storage/Validator/FileType.php +++ b/src/Appwrite/Storage/Validator/FileType.php @@ -64,7 +64,7 @@ class FileType extends Validator */ public function isValid($path) { - if(!\is_readable($path)) { + if (!\is_readable($path)) { return false; }