Skip to content

Commit

Permalink
Merge pull request #158 from GrahamCampbell/cs
Browse files Browse the repository at this point in the history
CS Fixes
  • Loading branch information
ramsey committed Nov 27, 2014
2 parents 16fa21c + ca67450 commit 1eed232
Show file tree
Hide file tree
Showing 30 changed files with 160 additions and 170 deletions.
4 changes: 2 additions & 2 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __isset($name)

public function getArrayCopy()
{
return array(
return [
'uid' => $this->uid,
'nickname' => $this->nickname,
'name' => $this->name,
Expand All @@ -65,7 +65,7 @@ public function getArrayCopy()
'urls' => $this->urls,
'gender' => $this->gender,
'locale' => $this->locale,
);
];
}

public function exchangeArray(array $data)
Expand Down
13 changes: 3 additions & 10 deletions src/Exception/IDPException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,13 @@ public function __construct($result)
$code = isset($result['code']) ? $result['code'] : 0;

if (isset($result['error'])) {

// OAuth 2.0 Draft 10 style
$message = $result['error'];

} elseif (isset($result['message'])) {

// cURL style
$message = $result['message'];

} else {

$message = 'Unknown Error.';

}

parent::__construct($message, $code);
Expand All @@ -34,7 +28,6 @@ public function __construct($result)
public function getType()
{
if (isset($this->result['error'])) {

$message = $this->result['error'];

if (is_string($message)) {
Expand All @@ -53,12 +46,12 @@ public function getType()
*/
public function __toString()
{
$str = $this->getType() . ': ';
$str = $this->getType().': ';

if ($this->code != 0) {
$str .= $this->code . ': ';
$str .= $this->code.': ';
}

return $str . $this->message;
return $str.$this->message;
}
}
2 changes: 1 addition & 1 deletion src/Grant/AuthorizationCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function prepRequestParams($defaultParams, $params)
return array_merge($defaultParams, $params);
}

public function handleResponse($response = array())
public function handleResponse($response = [])
{
return new AccessToken($response);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Grant/GrantInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface GrantInterface
{
public function __toString();

public function handleResponse($response = array());
public function handleResponse($response = []);

public function prepRequestParams($defaultParams, $params);
}
2 changes: 1 addition & 1 deletion src/Grant/RefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function prepRequestParams($defaultParams, $params)
return array_merge($defaultParams, $params);
}

public function handleResponse($response = array())
public function handleResponse($response = [])
{
return new AccessToken($response);
}
Expand Down
38 changes: 18 additions & 20 deletions src/Provider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace League\OAuth2\Client\Provider;

use Guzzle\Service\Client as GuzzleClient;
use Guzzle\Http\Exception\BadResponseException;
use League\OAuth2\Client\Token\AccessToken as AccessToken;
use Guzzle\Service\Client as GuzzleClient;
use League\OAuth2\Client\Exception\IDPException as IDPException;
use League\OAuth2\Client\Grant\GrantInterface;
use League\OAuth2\Client\Token\AccessToken as AccessToken;

abstract class AbstractProvider implements ProviderInterface
{
Expand All @@ -22,7 +22,7 @@ abstract class AbstractProvider implements ProviderInterface

public $uidKey = 'uid';

public $scopes = array();
public $scopes = [];

public $method = 'post';

Expand All @@ -40,15 +40,15 @@ abstract class AbstractProvider implements ProviderInterface
*/
protected $httpBuildEncType = 1;

public function __construct($options = array())
public function __construct($options = [])
{
foreach ($options as $option => $value) {
if (isset($this->{$option})) {
$this->{$option} = $value;
}
}

$this->setHttpClient(new GuzzleClient);
$this->setHttpClient(new GuzzleClient());
}

public function setHttpClient(GuzzleClient $client)
Expand Down Expand Up @@ -83,51 +83,51 @@ public function setScopes(array $scopes)
$this->scopes = $scopes;
}

public function getAuthorizationUrl($options = array())
public function getAuthorizationUrl($options = [])
{
$this->state = isset($options['state']) ? $options['state'] : md5(uniqid(rand(), true));

$params = array(
$params = [
'client_id' => $this->clientId,
'redirect_uri' => $this->redirectUri,
'state' => $this->state,
'scope' => is_array($this->scopes) ? implode($this->scopeSeparator, $this->scopes) : $this->scopes,
'response_type' => isset($options['response_type']) ? $options['response_type'] : 'code',
'approval_prompt' => 'auto'
);
'approval_prompt' => 'auto',
];

return $this->urlAuthorize() . '?' . $this->httpBuildQuery($params, '', '&');
return $this->urlAuthorize().'?'.$this->httpBuildQuery($params, '', '&');
}

// @codeCoverageIgnoreStart
public function authorize($options = array())
public function authorize($options = [])
{
header('Location: ' . $this->getAuthorizationUrl($options));
header('Location: '.$this->getAuthorizationUrl($options));
exit;
}
// @codeCoverageIgnoreEnd

public function getAccessToken($grant = 'authorization_code', $params = array())
public function getAccessToken($grant = 'authorization_code', $params = [])
{
if (is_string($grant)) {
// PascalCase the grant. E.g: 'authorization_code' becomes 'AuthorizationCode'
$className = str_replace(' ', '', ucwords(str_replace(array('-', '_'), ' ', $grant)));
$className = str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $grant)));
$grant = 'League\\OAuth2\\Client\\Grant\\'.$className;
if (! class_exists($grant)) {
throw new \InvalidArgumentException('Unknown grant "'.$grant.'"');
}
$grant = new $grant;
$grant = new $grant();
} elseif (! $grant instanceof GrantInterface) {
$message = get_class($grant).' is not an instance of League\OAuth2\Client\Grant\GrantInterface';
throw new \InvalidArgumentException($message);
}

$defaultParams = array(
$defaultParams = [
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret,
'redirect_uri' => $this->redirectUri,
'grant_type' => $grant,
);
];

$requestParams = $grant->prepRequestParams($defaultParams, $params);

Expand All @@ -137,7 +137,7 @@ public function getAccessToken($grant = 'authorization_code', $params = array())
// @codeCoverageIgnoreStart
// No providers included with this library use get but 3rd parties may
$client = $this->getHttpClient();
$client->setBaseUrl($this->urlAccessToken() . '?' . $this->httpBuildQuery($requestParams, '', '&'));
$client->setBaseUrl($this->urlAccessToken().'?'.$this->httpBuildQuery($requestParams, '', '&'));
$request = $client->send();
$response = $request->getBody();
break;
Expand Down Expand Up @@ -235,7 +235,6 @@ protected function fetchUserDetails(AccessToken $token)
$url = $this->urlUserDetails($token);

try {

$client = $this->getHttpClient();
$client->setBaseUrl($url);

Expand All @@ -245,7 +244,6 @@ protected function fetchUserDetails(AccessToken $token)

$request = $client->get()->send();
$response = $request->getBody();

} catch (BadResponseException $e) {
// @codeCoverageIgnoreStart
$raw_response = explode("\n", $e->getResponse());
Expand Down
13 changes: 6 additions & 7 deletions src/Provider/Eventbrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@

class Eventbrite extends AbstractProvider
{

public function __construct($options)
{
parent::__construct($options);
$this->headers = array(
'Authorization' => 'Bearer'
);
$this->headers = [
'Authorization' => 'Bearer',
];
}

public function urlAuthorize()
Expand All @@ -32,11 +31,11 @@ public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token)

public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token)
{
$user = new User;
$user->exchangeArray(array(
$user = new User();
$user->exchangeArray([
'uid' => $response->user->user_id,
'email' => $response->user->email,
));
]);

return $user;
}
Expand Down
14 changes: 7 additions & 7 deletions src/Provider/Facebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Facebook extends AbstractProvider
{
public $scopes = array('offline_access', 'email', 'read_stream');
public $scopes = ['offline_access', 'email', 'read_stream'];
public $responseType = 'string';

public function urlAuthorize()
Expand All @@ -27,20 +27,20 @@ public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token)
public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token)
{
$client = $this->getHttpClient();
$client->setBaseUrl('https://graph.facebook.com/me/picture?type=normal&access_token=' . $token->accessToken);
$client->setBaseUrl('https://graph.facebook.com/me/picture?type=normal&access_token='.$token->accessToken);
$request = $client->get()->send();
$info = $request->getInfo();
$imageUrl = $info['url'];

$user = new User;
$user = new User();

$username = (isset($response->username)) ? $response->username : null;
$email = (isset($response->email)) ? $response->email : null;
$location = (isset($response->hometown->name)) ? $response->hometown->name : null;
$description = (isset($response->bio)) ? $response->bio : null;
$imageUrl = ($imageUrl) ?: null;

$user->exchangeArray(array(
$user->exchangeArray([
'uid' => $response->id,
'nickname' => $username,
'name' => $response->name,
Expand All @@ -50,8 +50,8 @@ public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $
'location' => $location,
'description' => $description,
'imageurl' => $imageUrl,
'urls' => array( 'Facebook' => $response->link ),
));
'urls' => [ 'Facebook' => $response->link ],
]);

return $user;
}
Expand All @@ -68,6 +68,6 @@ public function userEmail($response, \League\OAuth2\Client\Token\AccessToken $to

public function userScreenName($response, \League\OAuth2\Client\Token\AccessToken $token)
{
return array($response->first_name, $response->last_name);
return [$response->first_name, $response->last_name];
}
}
12 changes: 6 additions & 6 deletions src/Provider/Github.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token)

public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token)
{
$user = new User;
$user = new User();

$name = (isset($response->name)) ? $response->name : null;
$email = (isset($response->email)) ? $response->email : null;

$user->exchangeArray(array(
$user->exchangeArray([
'uid' => $response->id,
'nickname' => $response->login,
'name' => $name,
'email' => $email,
'urls' =>array(
'GitHub' => 'http://github.com/' . $response->login,
),
));
'urls' => [
'GitHub' => 'http://github.com/'.$response->login,
],
]);

return $user;
}
Expand Down
14 changes: 7 additions & 7 deletions src/Provider/Google.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ class Google extends AbstractProvider
{
public $scopeSeparator = ' ';

public $scopes = array(
public $scopes = [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email'
);
'https://www.googleapis.com/auth/userinfo.email',
];

public function urlAuthorize()
{
Expand All @@ -32,18 +32,18 @@ public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $
{
$response = (array) $response;

$user = new User;
$user = new User();

$imageUrl = (isset($response['picture'])) ? $response['picture'] : null;

$user->exchangeArray(array(
$user->exchangeArray([
'uid' => $response['id'],
'name' => $response['name'],
'firstname' => $response['given_name'],
'lastName' => $response['family_name'],
'email' => $response['email'],
'imageUrl' => $imageUrl,
));
]);

return $user;
}
Expand All @@ -60,6 +60,6 @@ public function userEmail($response, \League\OAuth2\Client\Token\AccessToken $to

public function userScreenName($response, \League\OAuth2\Client\Token\AccessToken $token)
{
return array($response->given_name, $response->family_name);
return [$response->given_name, $response->family_name];
}
}
Loading

0 comments on commit 1eed232

Please sign in to comment.