Skip to content

Commit

Permalink
Apply fixes from StyleCI (#618)
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue authored Mar 22, 2017
1 parent ab33151 commit f4a1933
Show file tree
Hide file tree
Showing 22 changed files with 108 additions and 131 deletions.
17 changes: 8 additions & 9 deletions src/Foundation/ServiceProviders/OpenPlatformServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
namespace EasyWeChat\Foundation\ServiceProviders;

use EasyWeChat\Encryption\Encryptor;
use EasyWeChat\OpenPlatform\AccessToken;
use EasyWeChat\OpenPlatform\Authorization;
use EasyWeChat\OpenPlatform\AuthorizerToken;
use EasyWeChat\OpenPlatform\AccessToken;
use EasyWeChat\OpenPlatform\Components\Authorizer;
use EasyWeChat\OpenPlatform\EventHandlers\Authorized;
use EasyWeChat\OpenPlatform\EventHandlers\UpdateAuthorized;
use EasyWeChat\OpenPlatform\EventHandlers\Unauthorized;
use EasyWeChat\OpenPlatform\EventHandlers\ComponentVerifyTicket;
use EasyWeChat\OpenPlatform\EventHandlers\Unauthorized;
use EasyWeChat\OpenPlatform\EventHandlers\UpdateAuthorized;
use EasyWeChat\OpenPlatform\Guard;
use EasyWeChat\OpenPlatform\OpenPlatform;
use EasyWeChat\OpenPlatform\VerifyTicket;
Expand Down Expand Up @@ -106,7 +106,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 @@ -122,18 +122,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']);
};
}

}
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();
}
}
1 change: 0 additions & 1 deletion src/OpenPlatform/EventHandlers/EventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@ interface EventHandler
* @return mixed
*/
public function handle(Collection $message);

}
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
16 changes: 8 additions & 8 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 @@ -61,11 +61,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 @@ -122,7 +121,7 @@ public function listen($callback = null)
}

/**
* @inheritdoc
* {@inheritdoc}
*/
protected function handleMessage($message)
{
Expand All @@ -143,7 +142,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 @@ -161,12 +160,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
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: 0 additions & 2 deletions tests/Js/JsJsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,3 @@ public function testSetUrl()
}
}
}


Loading

0 comments on commit f4a1933

Please sign in to comment.