1
0
Fork 0
mirror of synced 2024-06-26 18:20:43 +12:00

PHP CS fixer

This commit is contained in:
eldadfux 2019-10-01 07:34:01 +03:00
parent 38b472aa83
commit e411590cf6
5 changed files with 33 additions and 28 deletions

View file

@ -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

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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';

View file

@ -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;
}
}