Skip to content

Commit 624a07d

Browse files
committed
Code style cleanup
1 parent 9c81baf commit 624a07d

14 files changed

+18
-61
lines changed

src/GrantType/RefreshToken.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -73,32 +73,32 @@ public function getRawData(SignerInterface $clientCredentialsSigner, $refreshTok
7373
*/
7474
protected function getPostBody($refreshToken)
7575
{
76-
if (Helper::guzzleIs('>=', '6')) {
77-
$data = [
76+
if (Helper::guzzleIs('>=', '6')) {
77+
$data = [
7878
'grant_type' => 'refresh_token',
7979
// If no refresh token was provided to the method, use the one
8080
// provided to the constructor.
8181
'refresh_token' => $refreshToken ?: $this->config['refresh_token'],
8282
];
8383

84-
if ($this->config['scope']) {
85-
$data['scope'] = $this->config['scope'];
86-
}
84+
if ($this->config['scope']) {
85+
$data['scope'] = $this->config['scope'];
86+
}
8787

88-
return \GuzzleHttp\Psr7\stream_for(http_build_query($data, '', '&'));
89-
}
88+
return \GuzzleHttp\Psr7\stream_for(http_build_query($data, '', '&'));
89+
}
9090

91-
$postBody = new PostBody();
92-
$postBody->replaceFields([
91+
$postBody = new PostBody();
92+
$postBody->replaceFields([
9393
'grant_type' => 'refresh_token',
9494
// If no refresh token was provided to the method, use the one
9595
// provided to the constructor.
9696
'refresh_token' => $refreshToken ?: $this->config['refresh_token'],
9797
]);
9898

99-
if ($this->config['scope']) {
99+
if ($this->config['scope']) {
100100
$postBody->setField('scope', $this->config['scope']);
101-
}
101+
}
102102

103103
return $postBody;
104104
}

tests/BaseTestCase.php

-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
class BaseTestCase extends \PHPUnit_Framework_TestCase
1111
{
12-
1312
protected function createRequest($method, $uri, $options=[])
1413
{
1514
return Helper::guzzleIs('>=', 6)?
@@ -35,7 +34,6 @@ protected function getQueryStringValue($request, $field)
3534
$values = $this->parseQueryString($query_string);
3635

3736
return array_key_exists($field, $values)? $values[$field]: null;
38-
3937
}
4038

4139
protected function getFormPostBodyValue($request, $field)
@@ -49,7 +47,6 @@ protected function getFormPostBodyValue($request, $field)
4947
$values = $this->parseQueryString($query_string);
5048

5149
return array_key_exists($field, $values)? $values[$field]: null;
52-
5350
}
5451

5552
protected function parseQueryString($query_string)
@@ -73,5 +70,4 @@ protected function setPostBody($request, array $data=[])
7370

7471
return $request;
7572
}
76-
7773
}

tests/GrantType/AuthorizationCodeTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
use GuzzleHttp\HandlerStack;
88
use GuzzleHttp\Middleware;
99
use GuzzleHttp\Psr7\Response as Psr7Response;
10-
use GuzzleHttp\Psr7\Request as Psr7Request;
11-
use GuzzleHttp\Exception\RequestException;
1210
use GuzzleHttp\Message\Response;
1311
use GuzzleHttp\Stream\Stream;
1412
use GuzzleHttp\Subscriber\History;

tests/GrantType/ClientCredentialsTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use GuzzleHttp\HandlerStack;
1010
use GuzzleHttp\Middleware;
1111
use GuzzleHttp\Psr7\Response as Psr7Response;
12-
use GuzzleHttp\Psr7\Request as Psr7Request;
1312
use GuzzleHttp\Subscriber\Mock as MockResponder;
1413
use GuzzleHttp\Subscriber\History;
1514
use GuzzleHttp\Message\Response;

tests/GrantType/PasswordCredentialsTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use GuzzleHttp\HandlerStack;
1010
use GuzzleHttp\Middleware;
1111
use GuzzleHttp\Psr7\Response as Psr7Response;
12-
use GuzzleHttp\Psr7\Request as Psr7Request;
1312
use GuzzleHttp\Subscriber\Mock as MockResponder;
1413
use GuzzleHttp\Subscriber\History;
1514
use GuzzleHttp\Message\Response;

tests/GrantType/RefreshTokenTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use GuzzleHttp\HandlerStack;
1010
use GuzzleHttp\Middleware;
1111
use GuzzleHttp\Psr7\Response as Psr7Response;
12-
use GuzzleHttp\Psr7\Request as Psr7Request;
1312
use GuzzleHttp\Subscriber\Mock as MockResponder;
1413
use GuzzleHttp\Subscriber\History;
1514
use GuzzleHttp\Message\Response;

tests/GrantType/Specific/GithubApplicationTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use GuzzleHttp\HandlerStack;
1212
use GuzzleHttp\Middleware;
1313
use GuzzleHttp\Psr7\Response as Psr7Response;
14-
use GuzzleHttp\Psr7\Request as Psr7Request;
1514
use GuzzleHttp\Subscriber\Mock as MockResponder;
1615
use GuzzleHttp\Subscriber\History;
1716
use kamermans\OAuth2\Utils\Helper;

tests/OAuth2HandlerTest.php

-10
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,11 @@
22

33
namespace kamermans\OAuth2\Tests;
44

5-
use GuzzleHttp\Client;
6-
use GuzzleHttp\Event\BeforeEvent;
7-
use GuzzleHttp\Event\ErrorEvent;
8-
use GuzzleHttp\Exception\RequestException;
9-
use GuzzleHttp\Message\Request;
10-
use GuzzleHttp\Message\Response;
11-
use kamermans\OAuth2\Utils\Helper;
125
use kamermans\OAuth2\OAuth2Handler;
136
use kamermans\OAuth2\Token\RawToken;
14-
use kamermans\OAuth2\Tests\BaseTestCase;
157

168
class OAuth2HandlerTest extends BaseTestCase
179
{
18-
1910
public function testConstruct()
2011
{
2112
$grant = $this->getMockBuilder('\kamermans\OAuth2\GrantType\ClientCredentials')
@@ -154,5 +145,4 @@ public function testValidTokenDoesNotCauseReauth()
154145
$sub->setAccessToken($tokenData);
155146
$sub->getAccessToken();
156147
}
157-
158148
}

tests/OAuth2MiddlewareTest.php

+7-19
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,13 @@
88
use GuzzleHttp\HandlerStack;
99
use GuzzleHttp\Middleware;
1010
use GuzzleHttp\Psr7\Response as Psr7Response;
11-
use GuzzleHttp\Psr7\Request as Psr7Request;
12-
use GuzzleHttp\Subscriber\Mock as MockResponder;
1311
use GuzzleHttp\Subscriber\History;
1412

1513
use kamermans\OAuth2\Utils\Helper;
1614
use kamermans\OAuth2\OAuth2Middleware;
17-
use kamermans\OAuth2\Token\RawToken;
18-
use kamermans\OAuth2\Tests\BaseTestCase;
1915

2016
class OAuth2MiddlewareTest extends BaseTestCase
2117
{
22-
2318
public function setUp()
2419
{
2520
if (Helper::guzzleIs('<', 6)) {
@@ -39,7 +34,6 @@ public function testConstruct()
3934

4035
public function testDoesNotTriggerForNonOAuthRequests()
4136
{
42-
4337
$reauth_container = [];
4438
$reauth_history = Middleware::history($reauth_container);
4539

@@ -97,14 +91,13 @@ public function testDoesNotTriggerForNonOAuthRequests()
9791
$this->assertCount(1, $container);
9892

9993
$this->assertSame('', $this->getHeader($container[0]['request'], 'Authorization'), "The request should not have been signed");
100-
10194
}
10295

10396
public function testTriggersSignerAndGrantDataProcessor()
10497
{
10598

10699
// A random access token helps avoid false pasitives due to caching
107-
$mock_access_token = md5(microtime(true).mt_rand(100000,999999));
100+
$mock_access_token = md5(microtime(true).mt_rand(100000, 999999));
108101

109102
$reauth_container = [];
110103
$reauth_history = Middleware::history($reauth_container);
@@ -167,7 +160,6 @@ public function testTriggersSignerAndGrantDataProcessor()
167160
// This proves that the access_token received from the reauth_client was used to authenticate this response
168161
$expected_auth_value = "Bearer $mock_access_token";
169162
$this->assertSame($expected_auth_value, $this->getHeader($container[0]['request'], 'Authorization'));
170-
171163
}
172164

173165
/**
@@ -177,7 +169,7 @@ public function testOnErrorDoesNotTriggerForNonOAuthRequests()
177169
{
178170

179171
// A random access token helps avoid false pasitives due to caching
180-
$mock_access_token = md5(microtime(true).mt_rand(100000,999999));
172+
$mock_access_token = md5(microtime(true).mt_rand(100000, 999999));
181173

182174
$reauth_container = [];
183175
$reauth_history = Middleware::history($reauth_container);
@@ -239,14 +231,13 @@ public function testOnErrorDoesNotTriggerForNonOAuthRequests()
239231

240232
$this->assertCount(0, $reauth_container);
241233
$this->assertCount(1, $container);
242-
243234
}
244235

245236
public function testOnErrorDoesTriggerForOAuthRequests()
246237
{
247238

248239
// A random access token helps avoid false pasitives due to caching
249-
$mock_access_token = md5(microtime(true).mt_rand(100000,999999));
240+
$mock_access_token = md5(microtime(true).mt_rand(100000, 999999));
250241

251242
$reauth_container = [];
252243
$reauth_history = Middleware::history($reauth_container);
@@ -314,14 +305,13 @@ public function testOnErrorDoesTriggerForOAuthRequests()
314305
// Note that if we didn't catch the HTTP 401, it would have thrown an exception
315306
$this->assertSame(401, $container[0]['response']->getStatusCode());
316307
$this->assertSame(200, $container[1]['response']->getStatusCode());
317-
318308
}
319309

320310
public function testOnErrorDoesNotTriggerForNon401Requests()
321311
{
322312

323313
// A random access token helps avoid false pasitives due to caching
324-
$mock_access_token = md5(microtime(true).mt_rand(100000,999999));
314+
$mock_access_token = md5(microtime(true).mt_rand(100000, 999999));
325315

326316
$reauth_container = [];
327317
$reauth_history = Middleware::history($reauth_container);
@@ -404,8 +394,8 @@ public function testTokenPersistenceIsUsed()
404394
{
405395

406396
// A random access token helps avoid false pasitives due to caching
407-
$mock_access_token_cached = md5(microtime(true).mt_rand(100000,999999));
408-
$mock_access_token = md5(microtime(true).mt_rand(100000,999999));
397+
$mock_access_token_cached = md5(microtime(true).mt_rand(100000, 999999));
398+
$mock_access_token = md5(microtime(true).mt_rand(100000, 999999));
409399

410400
$cached_token = new \kamermans\OAuth2\Token\RawToken($mock_access_token_cached);
411401

@@ -478,13 +468,12 @@ public function testTokenPersistenceIsUsed()
478468
// This proves that the access_token received from the Persistence was used to authenticate this response, not the one from reauth
479469
$expected_auth_value = "Bearer $mock_access_token_cached";
480470
$this->assertSame($expected_auth_value, $this->getHeader($container[0]['request'], 'Authorization'));
481-
482471
}
483472

484473
public function testOnErrorDoesNotLoop()
485474
{
486475
// A random access token helps avoid false pasitives due to caching
487-
$mock_access_token = md5(microtime(true).mt_rand(100000,999999));
476+
$mock_access_token = md5(microtime(true).mt_rand(100000, 999999));
488477

489478
$reauth_container = [];
490479
$reauth_history = Middleware::history($reauth_container);
@@ -597,5 +586,4 @@ public function __DISABLED__testOnErrorDoesNotLoop()
597586
// Force an onError event, which triggers the signer and grant data processor
598587
$sub->onError($event);
599588
}
600-
601589
}

tests/OAuth2SubscriberTest.php

-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
use GuzzleHttp\Message\Response;
1111
use kamermans\OAuth2\Utils\Helper;
1212
use kamermans\OAuth2\OAuth2Subscriber;
13-
use kamermans\OAuth2\Token\RawToken;
14-
use kamermans\OAuth2\Tests\BaseTestCase;
1513

1614
class OAuth2SubscriberTest extends BaseTestCase
1715
{
18-
1916
public function setUp()
2017
{
2118
if (Helper::guzzleIs('>=', 6)) {

tests/Signer/AccessToken/BasicAuthTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace kamermans\OAuth2\Tests\Signer\AccessToken;
44

5-
use kamermans\OAuth2\Utils\Helper;
65
use kamermans\OAuth2\Tests\BaseTestCase;
76
use kamermans\OAuth2\Signer\AccessToken\BasicAuth;
87

tests/Signer/AccessToken/QueryStringTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace kamermans\OAuth2\Tests\Signer\AccessToken;
44

5-
use GuzzleHttp\Message\Request;
6-
use kamermans\OAuth2\Utils\Helper;
75
use kamermans\OAuth2\Tests\BaseTestCase;
86
use kamermans\OAuth2\Signer\AccessToken\QueryString;
97

tests/Signer/ClientCredentials/BasicAuthTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace kamermans\OAuth2\Tests\Signer\ClientCredentials;
44

5-
use GuzzleHttp\Message\Request;
6-
use kamermans\OAuth2\Utils\Helper;
75
use kamermans\OAuth2\Tests\BaseTestCase;
86
use kamermans\OAuth2\Signer\ClientCredentials\BasicAuth;
97

tests/Signer/ClientCredentials/PostFormDataTest.php

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace kamermans\OAuth2\Tests\Signer\ClientCredentials;
44

5-
use GuzzleHttp\Post\PostBody;
6-
use GuzzleHttp\Message\Request;
7-
use kamermans\OAuth2\Utils\Helper;
85
use kamermans\OAuth2\Tests\BaseTestCase;
96
use kamermans\OAuth2\Signer\ClientCredentials\PostFormData;
107

0 commit comments

Comments
 (0)