From e411590cf678c7b2c3c2487bc864f0d153b5b6a6 Mon Sep 17 00:00:00 2001 From: eldadfux Date: Tue, 1 Oct 2019 07:34:01 +0300 Subject: [PATCH] PHP CS fixer --- src/Auth/OAuth.php | 2 +- src/Auth/OAuth/Gitlab.php | 22 +++++++++++----------- src/Auth/OAuth/Google.php | 25 +++++++++++++------------ src/Database/Validator/Collection.php | 2 +- src/Database/Validator/Structure.php | 10 +++++++--- 5 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/Auth/OAuth.php b/src/Auth/OAuth.php index ec1ae9eff6..70d7f448cf 100644 --- a/src/Auth/OAuth.php +++ b/src/Auth/OAuth.php @@ -99,7 +99,7 @@ abstract class OAuth curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); } - $headers[] = "Content-length: ".strlen($payload); + $headers[] = 'Content-length: '.strlen($payload); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // Send the request & save response to $response diff --git a/src/Auth/OAuth/Gitlab.php b/src/Auth/OAuth/Gitlab.php index 923add88f7..fbf21a4bd3 100644 --- a/src/Auth/OAuth/Gitlab.php +++ b/src/Auth/OAuth/Gitlab.php @@ -24,11 +24,11 @@ class Gitlab extends OAuth */ public function getLoginURL(): string { - return 'https://gitlab.com/oauth/authorize?' . - 'client_id=' . urlencode($this->appID) . - '&redirect_uri=' . urlencode($this->callback) . - '&scope=read_user' . - '&state=' . urlencode(json_encode($this->state)) . + return 'https://gitlab.com/oauth/authorize?'. + 'client_id='.urlencode($this->appID). + '&redirect_uri='.urlencode($this->callback). + '&scope=read_user'. + '&state='.urlencode(json_encode($this->state)). '&response_type=code'; } @@ -42,10 +42,10 @@ class Gitlab extends OAuth $accessToken = $this->request( 'POST', 'https://gitlab.com/oauth/token?'. - 'code=' . urlencode($code) . - '&client_id=' . urlencode($this->appID) . - '&client_secret=' . urlencode($this->appSecret) . - '&redirect_uri=' . urlencode($this->callback) . + 'code='.urlencode($code). + '&client_id='.urlencode($this->appID). + '&client_secret='.urlencode($this->appSecret). + '&redirect_uri='.urlencode($this->callback). '&grant_type=authorization_code' ); @@ -55,7 +55,6 @@ class Gitlab extends OAuth return $accessToken['access_token']; } - return ''; } @@ -115,9 +114,10 @@ class Gitlab extends OAuth protected function getUser(string $accessToken): array { if (empty($this->user)) { - $user = $this->request('GET', 'https://gitlab.com/api/v4/user?access_token=' . urlencode($accessToken)); + $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/Auth/OAuth/Google.php b/src/Auth/OAuth/Google.php index 252d629ab5..c07758d6b5 100644 --- a/src/Auth/OAuth/Google.php +++ b/src/Auth/OAuth/Google.php @@ -28,11 +28,11 @@ class Google extends OAuth */ public function getLoginURL(): string { - return 'https://accounts.google.com/o/oauth2/v2/auth?' . - 'client_id=' . urlencode($this->appID) . - '&redirect_uri=' . urlencode($this->callback) . - '&scope=https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile' . - '&state=' . urlencode(json_encode($this->state)) . + return 'https://accounts.google.com/o/oauth2/v2/auth?'. + 'client_id='.urlencode($this->appID). + '&redirect_uri='.urlencode($this->callback). + '&scope=https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile'. + '&state='.urlencode(json_encode($this->state)). '&response_type=code'; } @@ -45,12 +45,12 @@ class Google extends OAuth { $accessToken = $this->request( 'POST', - 'https://www.googleapis.com/oauth2/' . $this->version . '/token?' . - 'code=' . urlencode($code) . - '&client_id=' . urlencode($this->appID) . - '&client_secret=' . urlencode($this->appSecret) . - '&redirect_uri=' . urlencode($this->callback) . - '&scope=' . + 'https://www.googleapis.com/oauth2/'.$this->version.'/token?'. + 'code='.urlencode($code). + '&client_id='.urlencode($this->appID). + '&client_secret='.urlencode($this->appSecret). + '&redirect_uri='.urlencode($this->callback). + '&scope='. '&grant_type=authorization_code' ); @@ -119,9 +119,10 @@ class Google extends OAuth 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)); + $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/Database/Validator/Collection.php b/src/Database/Validator/Collection.php index 2d58da7bb1..dd08a62eba 100644 --- a/src/Database/Validator/Collection.php +++ b/src/Database/Validator/Collection.php @@ -40,7 +40,7 @@ class Collection extends Structure $document = new Document( array_merge($this->merge, ($document instanceof Document) ? $document->getArrayCopy() : $document) ); - + if (is_null($document->getCollection())) { $this->message = 'Missing collection attribute $collection'; diff --git a/src/Database/Validator/Structure.php b/src/Database/Validator/Structure.php index c2753d2769..f8d00f1e3a 100644 --- a/src/Database/Validator/Structure.php +++ b/src/Database/Validator/Structure.php @@ -186,18 +186,19 @@ 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'; } - + return false; } if ($ruleRequired && ('' === $value || null === $value)) { $this->message = 'Required property "'.$key.'" has no value'; + return false; } @@ -211,6 +212,7 @@ class Structure extends Validator if ($ruleArray) { // Array of values validation if (!is_array($value)) { $this->message = 'Property "'.$key.'" must be an array'; + return false; } @@ -219,12 +221,14 @@ class Structure extends Validator foreach ($value as $node) { if (!$validator->isValid($node)) { // Check if property is valid, if not required can also be empty $this->message = 'Property "'.$key.'" has invalid input. '.$validator->getDescription(); + return false; } } } else { // Single value validation if ((!$validator->isValid($value)) && !('' === $value && !$ruleRequired)) { // Error when value is not valid, and is not optional and empty $this->message = 'Property "'.$key.'" has invalid input. '.$validator->getDescription(); + return false; } }