Skip to content

Commit

Permalink
Style fixes (#117)
Browse files Browse the repository at this point in the history
 Applied fixes from StyleCI (#116)
  • Loading branch information
Nyholm authored Jul 18, 2016
1 parent 14992b9 commit 7af5503
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .styleci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
preset: symfony

finder:
paths:
path:
- "src"
- "tests"

Expand Down
8 changes: 4 additions & 4 deletions src/Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected function getAccessTokenFromCode(LinkedInUrlGeneratorInterface $urlGene
throw new LinkedInException('Could not get access token: The response from LinkedIn.com was empty.');
}

$tokenData = array_merge(array('access_token' => null, 'expires_in' => null), $response);
$tokenData = array_merge(['access_token' => null, 'expires_in' => null], $response);
$token = new AccessToken($tokenData['access_token'], $tokenData['expires_in']);

if (!$token->hasToken()) {
Expand All @@ -145,18 +145,18 @@ protected function getAccessTokenFromCode(LinkedInUrlGeneratorInterface $urlGene
/**
* {@inheritdoc}
*/
public function getLoginUrl(LinkedInUrlGeneratorInterface $urlGenerator, $options = array())
public function getLoginUrl(LinkedInUrlGeneratorInterface $urlGenerator, $options = [])
{
// Generate a state
$this->establishCSRFTokenState();

// Build request params
$requestParams = array_merge(array(
$requestParams = array_merge([
'response_type' => 'code',
'client_id' => $this->appId,
'state' => $this->getStorage()->get('state'),
'redirect_uri' => null,
), $options);
], $options);

// Save the redirect url for later
$this->getStorage()->set('redirect_uri', $requestParams['redirect_uri']);
Expand Down
2 changes: 1 addition & 1 deletion src/AuthenticatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function fetchNewAccessToken(LinkedInUrlGeneratorInterface $urlGenerator)
*
* @return string
*/
public function getLoginUrl(LinkedInUrlGeneratorInterface $urlGenerator, $options = array());
public function getLoginUrl(LinkedInUrlGeneratorInterface $urlGenerator, $options = []);

/**
* Clear the storage.
Expand Down
2 changes: 1 addition & 1 deletion src/Http/LinkedInUrlGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ interface LinkedInUrlGeneratorInterface
*
* @return string The URL for the given parameters. The URL query MUST be build with PHP_QUERY_RFC3986
*/
public function getUrl($name, $path = '', $params = array());
public function getUrl($name, $path = '', $params = []);
}
1 change: 0 additions & 1 deletion src/Http/RequestManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public function setMessageFactory(MessageFactory $messageFactory)
}

/**
*
* @return \Http\Message\MessageFactory
*/
private function getMessageFactory()
Expand Down
8 changes: 4 additions & 4 deletions src/Http/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ class UrlGenerator implements UrlGeneratorInterface
*
* A list of params that might be in the query string
*/
public static $knownLinkedInParams = array('state', 'code', 'access_token', 'user');
public static $knownLinkedInParams = ['state', 'code', 'access_token', 'user'];

/**
* @var array domainMap
*
* Maps aliases to LinkedIn domains.
*/
public static $domainMap = array(
public static $domainMap = [
'api' => 'https://api.linkedin.com/',
'www' => 'https://www.linkedin.com/',
);
];

/**
* @var bool
Expand All @@ -34,7 +34,7 @@ class UrlGenerator implements UrlGeneratorInterface
/**
* {@inheritdoc}
*/
public function getUrl($name, $path = '', $params = array())
public function getUrl($name, $path = '', $params = [])
{
$url = self::$domainMap[$name];
if ($path) {
Expand Down
12 changes: 6 additions & 6 deletions src/LinkedIn.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ public function isAuthenticated()
return false;
}

$user = $this->api('GET', '/v1/people/~:(id,firstName,lastName)', array('format' => 'json', 'response_data_type' => 'array'));
$user = $this->api('GET', '/v1/people/~:(id,firstName,lastName)', ['format' => 'json', 'response_data_type' => 'array']);

return !empty($user['id']);
}

/**
* {@inheritdoc}
*/
public function api($method, $resource, array $options = array())
public function api($method, $resource, array $options = [])
{
// Add access token to the headers
$options['headers']['Authorization'] = sprintf('Bearer %s', (string) $this->getAccessToken());
Expand All @@ -117,7 +117,7 @@ public function api($method, $resource, array $options = array())
$url = $this->getUrlGenerator()->getUrl(
'api',
$resource,
isset($options['query']) ? $options['query'] : array()
isset($options['query']) ? $options['query'] : []
);

$body = isset($options['body']) ? $options['body'] : null;
Expand Down Expand Up @@ -170,7 +170,7 @@ protected function filterRequestOption(array &$options)
/**
* {@inheritdoc}
*/
public function getLoginUrl($options = array())
public function getLoginUrl($options = [])
{
$urlGenerator = $this->getUrlGenerator();

Expand All @@ -190,7 +190,7 @@ public function getLoginUrl($options = array())
*
* @return mixed
*/
public function get($resource, array $options = array())
public function get($resource, array $options = [])
{
return $this->api('GET', $resource, $options);
}
Expand All @@ -203,7 +203,7 @@ public function get($resource, array $options = array())
*
* @return mixed
*/
public function post($resource, array $options = array())
public function post($resource, array $options = [])
{
return $this->api('POST', $resource, $options);
}
Expand Down
8 changes: 4 additions & 4 deletions src/LinkedInInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function isAuthenticated();
*
* @return mixed this depends on the response_data_type parameter.
*/
public function api($method, $resource, array $options = array());
public function api($method, $resource, array $options = []);

/**
* Get a login URL where the user can put his/hers LinkedIn credentials and authorize the application.
Expand All @@ -55,7 +55,7 @@ public function api($method, $resource, array $options = array());
*
* @return string The URL for the login flow
*/
public function getLoginUrl($options = array());
public function getLoginUrl($options = []);

/**
* See docs for LinkedIn::api().
Expand All @@ -65,7 +65,7 @@ public function getLoginUrl($options = array());
*
* @return mixed
*/
public function get($resource, array $options = array());
public function get($resource, array $options = []);

/**
* See docs for LinkedIn::api().
Expand All @@ -75,7 +75,7 @@ public function get($resource, array $options = array());
*
* @return mixed
*/
public function post($resource, array $options = array());
public function post($resource, array $options = []);

/**
* Clear the data storage. This will forget everything about the user and authentication process.
Expand Down
2 changes: 1 addition & 1 deletion src/Storage/BaseDataStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
abstract class BaseDataStorage implements DataStorageInterface
{
public static $validKeys = array('state', 'code', 'access_token', 'redirect_uri');
public static $validKeys = ['state', 'code', 'access_token', 'redirect_uri'];

/**
* {@inheritdoc}
Expand Down
50 changes: 25 additions & 25 deletions tests/AuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ public function testGetLoginUrl()
{
$expected = 'loginUrl';
$state = 'random';
$params = array(
$params = [
'response_type' => 'code',
'client_id' => self::APP_ID,
'redirect_uri' => null,
'state' => $state,
);
];

$storage = $this->getMock('Happyr\LinkedIn\Storage\DataStorageInterface');
$storage->method('get')->with('state')->willReturn($state);

$auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('establishCSRFTokenState', 'getStorage'), array($this->getRequestManagerMock(), self::APP_ID, self::APP_SECRET));
$auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['establishCSRFTokenState', 'getStorage'], [$this->getRequestManagerMock(), self::APP_ID, self::APP_SECRET]);
$auth->expects($this->exactly(2))->method('establishCSRFTokenState')->willReturn(null);
$auth->method('getStorage')->will($this->returnValue($storage));

Expand All @@ -47,20 +47,20 @@ public function testGetLoginUrl()
* Test with a url in the param
*/
$otherUrl = 'otherUrl';
$scope = array('foo', 'bar', 'baz');
$params = array(
$scope = ['foo', 'bar', 'baz'];
$params = [
'response_type' => 'code',
'client_id' => self::APP_ID,
'redirect_uri' => $otherUrl,
'state' => $state,
'scope' => 'foo bar baz',
);
];

$generator = m::mock('Happyr\LinkedIn\Http\LinkedInUrlGeneratorInterface')
->shouldReceive('getUrl')->once()->with('www', 'oauth/v2/authorization', $params)->andReturn($expected)
->getMock();

$this->assertEquals($expected, $auth->getLoginUrl($generator, array('redirect_uri' => $otherUrl, 'scope' => $scope)));
$this->assertEquals($expected, $auth->getLoginUrl($generator, ['redirect_uri' => $otherUrl, 'scope' => $scope]));
}

public function testFetchNewAccessToken()
Expand All @@ -72,7 +72,7 @@ public function testFetchNewAccessToken()
->shouldReceive('set')->once()->with('access_token', 'at')
->getMock();

$auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('getCode', 'getStorage', 'getAccessTokenFromCode'), array(), '', false);
$auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['getCode', 'getStorage', 'getAccessTokenFromCode'], [], '', false);
$auth->expects($this->any())->method('getStorage')->will($this->returnValue($storage));
$auth->expects($this->once())->method('getAccessTokenFromCode')->with($generator, $code)->will($this->returnValue('at'));
$auth->expects($this->once())->method('getCode')->will($this->returnValue($code));
Expand All @@ -91,7 +91,7 @@ public function testFetchNewAccessTokenFail()
->shouldReceive('clearAll')->once()
->getMock();

$auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('getCode', 'getStorage', 'getAccessTokenFromCode'), array(), '', false);
$auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['getCode', 'getStorage', 'getAccessTokenFromCode'], [], '', false);
$auth->expects($this->any())->method('getStorage')->will($this->returnValue($storage));
$auth->expects($this->once())->method('getAccessTokenFromCode')->with($generator, $code)->willThrowException(new LinkedInException());
$auth->expects($this->once())->method('getCode')->will($this->returnValue($code));
Expand All @@ -107,7 +107,7 @@ public function testFetchNewAccessTokenNoCode()
->shouldReceive('get')->once()->with('access_token')->andReturn('baz')
->getMock();

$auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('getCode', 'getStorage'), array(), '', false);
$auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['getCode', 'getStorage'], [], '', false);
$auth->expects($this->any())->method('getStorage')->will($this->returnValue($storage));
$auth->expects($this->once())->method('getCode');

Expand All @@ -123,7 +123,7 @@ public function testGetAccessTokenFromCodeEmptyString()

$method = new \ReflectionMethod('Happyr\LinkedIn\Authenticator', 'getAccessTokenFromCode');
$method->setAccessible(true);
$auth = $this->getMock('Happyr\LinkedIn\Authenticator', array(), array(), '', false);
$auth = $this->getMock('Happyr\LinkedIn\Authenticator', [], [], '', false);

$method->invoke($auth, $generator, '');
}
Expand All @@ -137,7 +137,7 @@ public function testGetAccessTokenFromCodeNull()

$method = new \ReflectionMethod('Happyr\LinkedIn\Authenticator', 'getAccessTokenFromCode');
$method->setAccessible(true);
$auth = $this->getMock('Happyr\LinkedIn\Authenticator', array(), array(), '', false);
$auth = $this->getMock('Happyr\LinkedIn\Authenticator', [], [], '', false);

$method->invoke($auth, $generator, null);
}
Expand All @@ -151,7 +151,7 @@ public function testGetAccessTokenFromCodeFalse()

$method = new \ReflectionMethod('Happyr\LinkedIn\Authenticator', 'getAccessTokenFromCode');
$method->setAccessible(true);
$auth = $this->getMock('Happyr\LinkedIn\Authenticator', array(), array(), '', false);
$auth = $this->getMock('Happyr\LinkedIn\Authenticator', [], [], '', false);

$method->invoke($auth, $generator, false);
}
Expand All @@ -169,7 +169,7 @@ public function testGetAccessTokenFromCode()
)->andReturn('url')
->getMock();

$response = array('access_token' => 'foobar', 'expires_in' => 10);
$response = ['access_token' => 'foobar', 'expires_in' => 10];
$auth = $this->prepareGetAccessTokenFromCode($code, $response);
$token = $method->invoke($auth, $generator, $code);
$this->assertEquals('foobar', $token, 'Standard get access token form code');
Expand All @@ -191,7 +191,7 @@ public function testGetAccessTokenFromCodeNoTokenInResponse()
)->andReturn('url')
->getMock();

$response = array('foo' => 'bar');
$response = ['foo' => 'bar'];
$auth = $this->prepareGetAccessTokenFromCode($code, $response);
$this->assertNull($method->invoke($auth, $generator, $code), 'Found array but no access token');
}
Expand Down Expand Up @@ -236,16 +236,16 @@ protected function prepareGetAccessTokenFromCode($code, $responseData)
$requestManager = m::mock('Happyr\LinkedIn\Http\RequestManager')
->shouldReceive('sendRequest')->once()->with('POST', 'url', [
'Content-Type' => 'application/x-www-form-urlencoded',
], http_build_query(array(
], http_build_query([
'grant_type' => 'authorization_code',
'code' => $code,
'redirect_uri' => $currentUrl,
'client_id' => self::APP_ID,
'client_secret' => self::APP_SECRET,
)))->andReturn($response)
]))->andReturn($response)
->getMock();

$auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('getStorage'), array($requestManager, self::APP_ID, self::APP_SECRET));
$auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['getStorage'], [$requestManager, self::APP_ID, self::APP_SECRET]);
$auth->expects($this->any())->method('getStorage')->will($this->returnValue($storage));

return $auth;
Expand All @@ -259,11 +259,11 @@ public function testEstablishCSRFTokenState()
$storage = m::mock('Happyr\LinkedIn\Storage\DataStorageInterface')
->shouldReceive('get')->with('state')->andReturn(null, 'state')
->shouldReceive('set')->once()->with('state', \Mockery::on(function (&$param) {
return !empty($param);
}))
return !empty($param);
}))
->getMock();

$auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('getStorage'), array(), '', false);
$auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['getStorage'], [], '', false);
$auth->expects($this->any())->method('getStorage')->will($this->returnValue($storage));

// Make sure we only set the state once
Expand All @@ -278,7 +278,7 @@ public function testGetCodeEmpty()

$method = new \ReflectionMethod('Happyr\LinkedIn\Authenticator', 'getCode');
$method->setAccessible(true);
$auth = $this->getMock('Happyr\LinkedIn\Authenticator', array(), array(), '', false);
$auth = $this->getMock('Happyr\LinkedIn\Authenticator', [], [], '', false);

$this->assertNull($method->invoke($auth));
}
Expand All @@ -295,7 +295,7 @@ public function testGetCode()
->shouldReceive('get')->once()->with('state')->andReturn($state)
->getMock();

$auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('getStorage'), array(), '', false);
$auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['getStorage'], [], '', false);
$auth->expects($this->once())->method('getStorage')->will($this->returnValue($storage));

$_REQUEST['code'] = 'foobar';
Expand All @@ -317,7 +317,7 @@ public function testGetCodeInvalidCode()
->shouldReceive('get')->once()->with('state')->andReturn('bazbar')
->getMock();

$auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('getStorage'), array(), '', false);
$auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['getStorage'], [], '', false);
$auth->expects($this->once())->method('getStorage')->will($this->returnValue($storage));

$_REQUEST['code'] = 'foobar';
Expand All @@ -335,7 +335,7 @@ public function testGetCodeUsedCode()
->shouldReceive('get')->once()->with('code')->andReturn('foobar')
->getMock();

$auth = $this->getMock('Happyr\LinkedIn\Authenticator', array('getStorage'), array(), '', false);
$auth = $this->getMock('Happyr\LinkedIn\Authenticator', ['getStorage'], [], '', false);
$auth->expects($this->once())->method('getStorage')->will($this->returnValue($storage));

$_REQUEST['code'] = 'foobar';
Expand Down
Loading

0 comments on commit 7af5503

Please sign in to comment.