Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply fixes from StyleCI #612

Merged
merged 1 commit into from
Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/OpenPlatform/Authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Authorization
{
use Caches;

const CACHE_KEY_ACCESS_TOKEN = 'easywechat.open_platform.authorizer_access_token';
const CACHE_KEY_ACCESS_TOKEN = 'easywechat.open_platform.authorizer_access_token';
const CACHE_KEY_REFRESH_TOKEN = 'easywechat.open_platform.authorizer_refresh_token';

/**
Expand Down Expand Up @@ -79,11 +79,12 @@ public function setAuthorizerAppId($authorizerAppId)
* Gets the authorizer app id, or throws if not found.
*
* @return string
*
* @throws Exception
*/
public function getAuthorizerAppId()
{
if (! $this->authorizerAppId) {
if (!$this->authorizerAppId) {
throw new Exception(
'Authorizer App Id is not present, you may not make the authorization yet.'
);
Expand Down Expand Up @@ -153,7 +154,7 @@ public function handleAuthorization()
/**
* Handles the authorizer access token: calls the API, saves the token.
*
* @return string The authorizer access token.
* @return string the authorizer access token
*/
public function handleAuthorizerAccessToken()
{
Expand Down Expand Up @@ -202,7 +203,7 @@ public function getAuthorizerInfo()
/**
* Saves the authorizer access token in cache.
*
* @param Collection|array $data Array structure from WeChat API result.
* @param Collection|array $data array structure from WeChat API result
*/
public function saveAuthorizerAccessToken($data)
{
Expand All @@ -226,7 +227,7 @@ public function getAuthorizerAccessToken()
/**
* Saves the authorizer refresh token in cache.
*
* @param Collection|array $data Array structure from WeChat API result.
* @param Collection|array $data array structure from WeChat API result
*/
public function saveAuthorizerRefreshToken($data)
{
Expand All @@ -239,7 +240,8 @@ public function saveAuthorizerRefreshToken($data)
* Gets the authorizer refresh token.
*
* @return string
* @throws Exception When refresh token is not present.
*
* @throws Exception when refresh token is not present
*/
public function getAuthorizerRefreshToken()
{
Expand Down Expand Up @@ -276,8 +278,8 @@ public function removeAuthorizerRefreshToken()
public function getAuthorizerAccessTokenKey()
{
return self::CACHE_KEY_ACCESS_TOKEN
. '.' . $this->appId
. '.' . $this->getAuthorizerAppId();
.'.'.$this->appId
.'.'.$this->getAuthorizerAppId();
}

/**
Expand All @@ -288,8 +290,7 @@ public function getAuthorizerAccessTokenKey()
public function getAuthorizerRefreshTokenKey()
{
return self::CACHE_KEY_REFRESH_TOKEN
. '.' . $this->appId
. '.' . $this->getAuthorizerAppId();
.'.'.$this->appId
.'.'.$this->getAuthorizerAppId();
}

}
}
6 changes: 2 additions & 4 deletions src/OpenPlatform/AuthorizerToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@
use EasyWeChat\Core\AccessToken as BaseAccessToken;

/**
* Class AuthorizerToken
* Class AuthorizerToken.
*
* AuthorizerToken is responsible for the access token of the authorizer,
* the complexity is that this access token also requires the refresh token
* of the authorizer which is acquired by the open platform authorization
* process.
*
* This completely overrides the original AccessToken.
*
* @package EasyWeChat\OpenPlatform
*/
class AuthorizerToken extends BaseAccessToken
{
Expand All @@ -55,7 +53,7 @@ class AuthorizerToken extends BaseAccessToken
/**
* AuthorizerAccessToken constructor.
*
* @param string $appId
* @param string $appId
* @param Authorization $authorization
*/
public function __construct($appId, Authorization $authorization)
Expand Down
6 changes: 3 additions & 3 deletions src/OpenPlatform/Components/AbstractComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ abstract class AbstractComponent extends AbstractAPI
* AbstractComponent constructor.
*
* @param AccessToken $accessToken
* @param array $config
* @param array $config
* @param $request
*/
public function __construct($accessToken, array $config, $request = null)
Expand All @@ -73,7 +73,8 @@ public function __construct($accessToken, array $config, $request = null)
* Get AppId.
*
* @return string
* @throws Exception When app id is not present.
*
* @throws Exception when app id is not present
*/
public function getAppId()
{
Expand Down Expand Up @@ -107,5 +108,4 @@ public function setAppId($appId)

return $this;
}

}
1 change: 0 additions & 1 deletion src/OpenPlatform/Components/Authorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,4 @@ public function setAuthorizerOption($authorizerAppId, $optionName, $optionValue)

return $this->parseJSON('json', [self::SET_AUTHORIZER_OPTION, $data]);
}

}
1 change: 0 additions & 1 deletion src/OpenPlatform/Components/PreAuthCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class PreAuthCode extends AbstractComponent
*/
protected $redirectUri;


/**
* Get pre auth code.
*
Expand Down
1 change: 1 addition & 0 deletions src/OpenPlatform/EventHandlers/Authorized.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function __construct(Authorization $authorization)
public function handle(Collection $message)
{
$this->authorization->setFromAuthMessage($message);

return $this->authorization->handleAuthorization();
}
}
2 changes: 1 addition & 1 deletion src/OpenPlatform/EventHandlers/Unauthorized.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
class Unauthorized extends Authorized
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public function handle(Collection $message)
{
Expand Down
18 changes: 9 additions & 9 deletions src/OpenPlatform/Guard.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@

class Guard extends ServerGuard
{
const EVENT_AUTHORIZED = 'authorized';
const EVENT_UNAUTHORIZED = 'unauthorized';
const EVENT_UPDATE_AUTHORIZED = 'updateauthorized';
const EVENT_AUTHORIZED = 'authorized';
const EVENT_UNAUTHORIZED = 'unauthorized';
const EVENT_UPDATE_AUTHORIZED = 'updateauthorized';
const EVENT_COMPONENT_VERIFY_TICKET = 'component_verify_ticket';

/**
Expand All @@ -51,7 +51,7 @@ class Guard extends ServerGuard
/**
* Guard constructor.
*
* @param string $token
* @param string $token
* @param Request $request
*/
public function __construct($token, Request $request = null)
Expand All @@ -72,11 +72,10 @@ public function setContainer(Container $container)
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function serve()
{

// If sees the `auth_code` query parameter in the url, that is,
// authorization is successful and it calls back, meanwhile, an
// ` authorized` event, which also includes the auth code, is sent
Expand Down Expand Up @@ -140,7 +139,7 @@ public function listen($callback = null)
}

/**
* @inheritdoc
* {@inheritdoc}
*/
protected function handleMessage($message)
{
Expand All @@ -156,7 +155,7 @@ protected function handleMessage($message)
if (is_array($result) || $result instanceof Collection) {
$message->merge($result);
} else {
if (! empty($result)) {
if (!empty($result)) {
$message->set('result', $result);
}
}
Expand All @@ -174,12 +173,13 @@ protected function handleMessage($message)
* @param $type
*
* @return EventHandlers\EventHandler
*
* @throws InvalidArgumentException
*/
protected function getDefaultHandler($type)
{
$handler = $this->container->offsetGet("open_platform.handlers.{$type}");
if (! $handler) {
if (!$handler) {
throw new InvalidArgumentException("EventHandler \"$type\" does not exists.");
}

Expand Down
11 changes: 5 additions & 6 deletions src/OpenPlatform/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function register(Container $pimple)
);
};

$pimple['open_platform.authorization'] = function($pimple) {
$pimple['open_platform.authorization'] = function ($pimple) {
return new Authorization(
$pimple['open_platform.authorizer'],
$pimple['config']['open_platform']['app_id'],
Expand All @@ -114,18 +114,17 @@ public function register(Container $pimple)
};

// Authorization events handlers.
$pimple['open_platform.handlers.component_verify_ticket'] = function($pimple) {
$pimple['open_platform.handlers.component_verify_ticket'] = function ($pimple) {
return new ComponentVerifyTicket($pimple['open_platform.verify_ticket']);
};
$pimple['open_platform.handlers.authorized'] = function($pimple) {
$pimple['open_platform.handlers.authorized'] = function ($pimple) {
return new Authorized($pimple['open_platform.authorization']);
};
$pimple['open_platform.handlers.updateauthorized'] = function($pimple) {
$pimple['open_platform.handlers.updateauthorized'] = function ($pimple) {
return new UpdateAuthorized($pimple['open_platform.authorization']);
};
$pimple['open_platform.handlers.unauthorized'] = function($pimple) {
$pimple['open_platform.handlers.unauthorized'] = function ($pimple) {
return new Unauthorized($pimple['open_platform.authorization']);
};
}

}
9 changes: 4 additions & 5 deletions src/OpenPlatform/Traits/Caches.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getCache()
* Gets the cached data.
*
* @param string $key
* @param mixed $default A default value or a callable to return the value.
* @param mixed $default a default value or a callable to return the value
*
* @return mixed
*/
Expand All @@ -75,8 +75,8 @@ public function get($key, $default = null)
* Sets the cached data.
*
* @param string $key
* @param mixed $value
* @param int $life Cache life time in seconds.
* @param mixed $value
* @param int $life cache life time in seconds
*
* @return bool
*/
Expand All @@ -96,5 +96,4 @@ public function remove($key)
{
return $this->getCache()->delete($key);
}

}
}
4 changes: 2 additions & 2 deletions src/OpenPlatform/VerifyTicket.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class VerifyTicket
* VerifyTicket constructor.
*
* @param string $appId
* @param Cache $cache
* @param Cache $cache
*/
public function __construct($appId, Cache $cache = null)
{
Expand Down Expand Up @@ -129,7 +129,7 @@ public function setCacheKey($cacheKey)
public function getCacheKey()
{
if (is_null($this->cacheKey)) {
return $this->prefix . $this->appId;
return $this->prefix.$this->appId;
}

return $this->cacheKey;
Expand Down
2 changes: 1 addition & 1 deletion tests/Core/CoreAbstractAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function testParseJSON()
$this->expectException(\EasyWeChat\Core\Exceptions\HttpException::class);
$this->expectExceptionMessage('Unknown');
$this->expectExceptionCode(24000);

$collection = $api->parseJSON('get', ['foo', ['bar']]);
$this->fail();
}
Expand Down
30 changes: 14 additions & 16 deletions tests/OpenPlatform/AuthorizationHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
*
* @author lixiao <[email protected]>
*/

use EasyWeChat\OpenPlatform\EventHandlers\Authorized;
use EasyWeChat\OpenPlatform\EventHandlers\Unauthorized;
use EasyWeChat\Support\Collection;

class AuthorizationHandlerTest extends AuthorizationTest
{

public function testAuthorized()
{
$appId = 'appid@123';
Expand All @@ -25,11 +23,11 @@ public function testAuthorized()
);

$message = [
'AppId' => 'open-platform-app-id',
'CreateTIme' => '1413192760',
'InfoType' => 'authorized',
'AuthorizerAppid' => 'authorizer-app-id',
'AuthorizationCode' => 'auth-code',
'AppId' => 'open-platform-app-id',
'CreateTIme' => '1413192760',
'InfoType' => 'authorized',
'AuthorizerAppid' => 'authorizer-app-id',
'AuthorizationCode' => 'auth-code',
'AuthorizationCodeExpiredTime' => '600',
];
$authorized = new Authorized($authorization);
Expand Down Expand Up @@ -58,21 +56,21 @@ public function testUnauthorized()

// Authorized => saves the tokens.
$message = [
'AppId' => 'open-platform-app-id',
'CreateTIme' => '1413192760',
'InfoType' => 'authorized',
'AuthorizerAppid' => 'authorizer-app-id',
'AuthorizationCode' => 'auth-code',
'AppId' => 'open-platform-app-id',
'CreateTIme' => '1413192760',
'InfoType' => 'authorized',
'AuthorizerAppid' => 'authorizer-app-id',
'AuthorizationCode' => 'auth-code',
'AuthorizationCodeExpiredTime' => '600',
];
$authorized = new Authorized($authorization);
$authorized->handle(new Collection($message));

// Unauthorized => removes the tokens.
$message = [
'AppId' => 'open-platform-app-id',
'CreateTIme' => '1413192760',
'InfoType' => 'authorized',
'AppId' => 'open-platform-app-id',
'CreateTIme' => '1413192760',
'InfoType' => 'authorized',
'AuthorizerAppid' => 'authorizer-app-id',
];
$authorized = new Unauthorized($authorization);
Expand All @@ -82,4 +80,4 @@ public function testUnauthorized()
$this->setExpectedException(\EasyWeChat\Core\Exception::class);
$this->assertNull($authorization->getAuthorizerRefreshToken());
}
}
}
Loading