diff --git a/.gitignore b/.gitignore index a1ea8af..d5e23cb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ /vendor composer.phar composer.lock +.php_cs.cache +.php_cs .DS_Store diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..e30aa56 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,8 @@ +in(__DIR__); + +return \Ely\CS\Config::create([ + 'visibility_required' => ['property', 'method'], + 'ternary_to_null_coalescing' => false, +])->setFinder($finder); diff --git a/.travis.yml b/.travis.yml index 2380116..419fa3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,15 @@ php: - 5.6 - 7.0 - 7.1 + - 7.2 env: matrix: - PREFER_LOWEST="--prefer-lowest" - PREFER_LOWEST="" + fast_finish: true + allow_failures: + - php: nightly before_script: - travis_retry composer self-update diff --git a/composer.json b/composer.json index 388bae6..d03d92a 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ }, "require-dev": { "phpunit/phpunit": "^4.8 || ^5.0", - "mockery/mockery": "~0.9" + "mockery/mockery": "~0.9", + "ely/php-code-style": "^0.2.0" }, "autoload": { "psr-4": { @@ -29,7 +30,7 @@ }, "autoload-dev": { "psr-4": { - "Ely\\OAuth2\\Client\\Test\\": "tests/src/" + "Ely\\OAuth2\\Client\\Test\\": "tests/" } } } diff --git a/src/Exception/IdentityProviderException.php b/src/Exception/IdentityProviderException.php index 8928407..dceef9d 100644 --- a/src/Exception/IdentityProviderException.php +++ b/src/Exception/IdentityProviderException.php @@ -3,7 +3,6 @@ namespace Ely\OAuth2\Client\Exception; use League\OAuth2\Client\Provider\Exception\IdentityProviderException as LeagueIdentityProviderException; -class IdentityProviderException extends LeagueIdentityProviderException -{ +class IdentityProviderException extends LeagueIdentityProviderException { } diff --git a/src/Provider.php b/src/Provider.php index 93ee2d3..ef54555 100644 --- a/src/Provider.php +++ b/src/Provider.php @@ -10,8 +10,7 @@ use Psr\Http\Message\ResponseInterface; /** * @method ResourceOwner getResourceOwner(AccessToken $token) */ -class Provider extends AbstractProvider -{ +class Provider extends AbstractProvider { use BearerAuthorizationTrait; const REDIRECT_URI_STATIC_PAGE = 'static_page'; @@ -20,32 +19,28 @@ class Provider extends AbstractProvider /** * @inheritdoc */ - public function getBaseAuthorizationUrl() - { + public function getBaseAuthorizationUrl() { return 'https://account.ely.by/oauth2/v1/' . $this->clientId; } /** * @inheritdoc */ - public function getBaseAccessTokenUrl(array $params) - { + public function getBaseAccessTokenUrl(array $params) { return 'https://account.ely.by/api/oauth2/v1/token'; } /** * @inheritdoc */ - public function getResourceOwnerDetailsUrl(AccessToken $token) - { + public function getResourceOwnerDetailsUrl(AccessToken $token) { return 'https://account.ely.by/api/account/v1/info'; } /** * @inheritdoc */ - protected function getAuthorizationParameters(array $options) - { + protected function getAuthorizationParameters(array $options) { $params = parent::getAuthorizationParameters($options); // client_id applied to base url // approval_prompt not supported @@ -57,8 +52,7 @@ class Provider extends AbstractProvider /** * @inheritdoc */ - protected function getDefaultScopes() - { + protected function getDefaultScopes() { return [ 'account_info', ]; @@ -67,8 +61,7 @@ class Provider extends AbstractProvider /** * @inheritdoc */ - protected function checkResponse(ResponseInterface $response, $data) - { + protected function checkResponse(ResponseInterface $response, $data) { $statusCode = $response->getStatusCode(); if ($statusCode !== 200) { $message = isset($data['message']) ? $data['message'] : $response->getReasonPhrase(); @@ -83,8 +76,8 @@ class Provider extends AbstractProvider * @param AccessToken $token * @return ResourceOwner */ - protected function createResourceOwner(array $response, AccessToken $token) - { + protected function createResourceOwner(array $response, AccessToken $token) { return new ResourceOwner($response); } + } diff --git a/src/ResourceOwner.php b/src/ResourceOwner.php index 83006c6..493b58a 100644 --- a/src/ResourceOwner.php +++ b/src/ResourceOwner.php @@ -4,8 +4,8 @@ namespace Ely\OAuth2\Client; use DateTime; use League\OAuth2\Client\Provider\ResourceOwnerInterface; -class ResourceOwner implements ResourceOwnerInterface -{ +class ResourceOwner implements ResourceOwnerInterface { + /** * Raw response * @@ -18,8 +18,7 @@ class ResourceOwner implements ResourceOwnerInterface * * @param array $response */ - public function __construct(array $response = []) - { + public function __construct(array $response = []) { $this->response = $response; } @@ -28,8 +27,7 @@ class ResourceOwner implements ResourceOwnerInterface * * @return string */ - public function getId() - { + public function getId() { return $this->response['id']; } @@ -38,8 +36,7 @@ class ResourceOwner implements ResourceOwnerInterface * * @return string */ - public function getUuid() - { + public function getUuid() { return $this->response['uuid']; } @@ -48,8 +45,7 @@ class ResourceOwner implements ResourceOwnerInterface * * @return string */ - public function getUsername() - { + public function getUsername() { return $this->response['username']; } @@ -59,8 +55,7 @@ class ResourceOwner implements ResourceOwnerInterface * * @return string|null */ - public function getEmail() - { + public function getEmail() { return isset($this->response['email']) ? $this->response['email'] : null; } @@ -69,8 +64,7 @@ class ResourceOwner implements ResourceOwnerInterface * * @return DateTime */ - public function getRegisteredAt() - { + public function getRegisteredAt() { return new DateTime('@' . $this->response['registeredAt']); } @@ -79,8 +73,7 @@ class ResourceOwner implements ResourceOwnerInterface * * @return string */ - public function getProfileLink() - { + public function getProfileLink() { return $this->response['profileLink']; } @@ -90,8 +83,7 @@ class ResourceOwner implements ResourceOwnerInterface * * @return string */ - public function getPreferredLanguage() - { + public function getPreferredLanguage() { return $this->response['preferredLanguage']; } @@ -101,8 +93,7 @@ class ResourceOwner implements ResourceOwnerInterface * * @return string */ - public function getSkinUrl() - { + public function getSkinUrl() { return "http://skinsystem.ely.by/skins/{$this->getUsername()}.png"; } @@ -111,10 +102,10 @@ class ResourceOwner implements ResourceOwnerInterface * * @return array */ - public function toArray() - { + public function toArray() { return array_merge($this->response, [ - 'skinUrl' => $this->getSkinUrl(), + 'skinUrl' => $this->getSkinUrl(), ]); } + } diff --git a/tests/ProviderTest.php b/tests/ProviderTest.php index 62a6f57..d2fbc9f 100644 --- a/tests/ProviderTest.php +++ b/tests/ProviderTest.php @@ -8,15 +8,14 @@ use League\OAuth2\Client\Token\AccessToken; use Mockery as m; use Psr\Http\Message\ResponseInterface; -class ProviderTest extends \PHPUnit_Framework_TestCase -{ +class ProviderTest extends \PHPUnit_Framework_TestCase { + /** * @var Provider */ protected $provider; - protected function setUp() - { + protected function setUp() { $this->provider = new Provider([ 'clientId' => 'mock_client_id', 'clientSecret' => 'mock_secret', @@ -24,21 +23,18 @@ class ProviderTest extends \PHPUnit_Framework_TestCase ]); } - public function tearDown() - { + public function tearDown() { m::close(); parent::tearDown(); } - public function testGetResourceOwnerDetailsUrl() - { + public function testGetResourceOwnerDetailsUrl() { $url = $this->provider->getResourceOwnerDetailsUrl(new AccessToken(['access_token' => 'mock_token'])); $uri = parse_url($url); $this->assertEquals('/api/account/v1/info', $uri['path']); } - public function testGetAuthorizationUrl() - { + public function testGetAuthorizationUrl() { $url = $this->provider->getAuthorizationUrl(); $uri = parse_url($url); parse_str($uri['query'], $query); @@ -53,8 +49,7 @@ class ProviderTest extends \PHPUnit_Framework_TestCase $this->assertNotNull($this->provider->getState()); } - public function testScopes() - { + public function testScopes() { $options = ['scope' => ['minecraft_server_session', 'account_info']]; $url = $this->provider->getAuthorizationUrl($options); @@ -62,8 +57,7 @@ class ProviderTest extends \PHPUnit_Framework_TestCase $this->assertContains(urlencode(implode(',', $options['scope'])), $url); } - public function testGetBaseAccessTokenUrl() - { + public function testGetBaseAccessTokenUrl() { $params = []; $url = $this->provider->getBaseAccessTokenUrl($params); @@ -72,8 +66,7 @@ class ProviderTest extends \PHPUnit_Framework_TestCase $this->assertEquals('/api/oauth2/v1/token', $uri['path']); } - public function testGetAccessToken() - { + public function testGetAccessToken() { /** @var m\Mock|ResponseInterface $response */ $response = m::mock(ResponseInterface::class); $response->shouldReceive('getBody')->andReturn($this->getAccessTokenResponse()); @@ -96,11 +89,10 @@ class ProviderTest extends \PHPUnit_Framework_TestCase * @expectedException \Ely\OAuth2\Client\Exception\IdentityProviderException * @expectedExceptionMessageRegExp /Exception message .+/ */ - public function testExceptionThrownWhenErrorObjectReceived() - { + public function testExceptionThrownWhenErrorObjectReceived() { $name = 'Error ' . uniqid(); $message = 'Exception message ' . uniqid(); - $status = rand(400, 600); + $status = mt_rand(400, 600); /** @var m\Mock|ResponseInterface $postResponse */ $postResponse = m::mock(ResponseInterface::class); $postResponse->shouldReceive('getBody')->andReturn(json_encode([ @@ -125,8 +117,7 @@ class ProviderTest extends \PHPUnit_Framework_TestCase * @expectedException \Ely\OAuth2\Client\Exception\IdentityProviderException * @expectedExceptionMessage Bad Gateway */ - public function testExceptionThrownOnIncorrectContentType() - { + public function testExceptionThrownOnIncorrectContentType() { /** @var m\Mock|ResponseInterface $postResponse */ $postResponse = m::mock(ResponseInterface::class); $postResponse->shouldReceive('getHeader')->andReturn(['content-type' => 'text/html; charset=UTF-8']); @@ -143,8 +134,7 @@ class ProviderTest extends \PHPUnit_Framework_TestCase $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']); } - public function testGetResourceOwner() - { + public function testGetResourceOwner() { /** @var m\Mock|ResponseInterface $postResponse */ $postResponse = m::mock(ResponseInterface::class); $postResponse->shouldReceive('getBody')->andReturn($this->getAccessTokenResponse()); @@ -162,8 +152,8 @@ class ProviderTest extends \PHPUnit_Framework_TestCase /** @var m\Mock|ClientInterface $client */ $client = m::mock(ClientInterface::class); $client->shouldReceive('send') - ->times(2) - ->andReturn($postResponse, $userResponse); + ->times(2) + ->andReturn($postResponse, $userResponse); $this->provider->setHttpClient($client); $token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']); @@ -172,12 +162,12 @@ class ProviderTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf(ResourceOwner::class, $user); } - private function getAccessTokenResponse() - { + private function getAccessTokenResponse() { return json_encode([ 'access_token' => 'mock_access_token', 'token_type' => 'bearer', 'expires_in' => 3600, ]); } + } diff --git a/tests/ResourceOwnerTest.php b/tests/ResourceOwnerTest.php index 137d4a7..7357424 100644 --- a/tests/ResourceOwnerTest.php +++ b/tests/ResourceOwnerTest.php @@ -3,53 +3,44 @@ namespace Ely\OAuth2\Client\Test; use Ely\OAuth2\Client\ResourceOwner; -class ResourceOwnerTest extends \PHPUnit_Framework_TestCase -{ - public function testGetId() - { +class ResourceOwnerTest extends \PHPUnit_Framework_TestCase { + + public function testGetId() { $this->assertEquals(1, $this->createModel()->getId()); } - public function testGetUuid() - { + public function testGetUuid() { $this->assertEquals('ffc8fdc9-5824-509e-8a57-c99b940fb996', $this->createModel()->getUuid()); } - public function testGetUsername() - { + public function testGetUsername() { $this->assertEquals('ErickSkrauch', $this->createModel()->getUsername()); } - public function testGetEmail() - { + public function testGetEmail() { $this->assertEquals('erickskrauch@ely.by', $this->createModel()->getEmail()); $this->assertNull($this->createModelWithoutEmail()->getEmail()); } - public function testGetRegisteredAt() - { + public function testGetRegisteredAt() { $registeredAt = $this->createModel()->getRegisteredAt(); $this->assertInstanceOf(\DateTime::class, $registeredAt); $this->assertEquals(1470566470, $registeredAt->getTimestamp()); } - public function testGetProfileLink() - { + public function testGetProfileLink() { $this->assertEquals('http://ely.by/u1', $this->createModel()->getProfileLink()); } - public function testGetPreferredLanguage() - { + public function testGetPreferredLanguage() { $this->assertEquals('be', $this->createModel()->getPreferredLanguage()); } - public function testGetSkinUrl() - { + public function testGetSkinUrl() { $this->assertEquals('http://skinsystem.ely.by/skins/ErickSkrauch.png', $this->createModel()->getSkinUrl()); } - public function testToArray() - { + public function testToArray() { $array = $this->createModel()->toArray(); $this->assertTrue(is_array($array)); $this->assertEquals(1, $array['id']); @@ -64,21 +55,19 @@ class ResourceOwnerTest extends \PHPUnit_Framework_TestCase $this->assertArrayNotHasKey('email', $array); } - private function createModelWithoutEmail() - { + private function createModelWithoutEmail() { $params = $this->getAllResponseParams(); unset($params['email']); return new ResourceOwner($params); } - private function createModel() - { + private function createModel() { return new ResourceOwner($this->getAllResponseParams()); } - private function getAllResponseParams() - { + private function getAllResponseParams() { return json_decode(file_get_contents(__DIR__ . '/data/identity-info-response.json'), true); } + }