From 1e4b446e3cce4e3aeeb1db1af5d8e7b56db45fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0rfan=20Evrens?= Date: Mon, 29 Jun 2015 04:40:24 +0300 Subject: [PATCH 1/3] Tiny improvements. --- .gitignore | 1 + src/Exceptions/LoginError.php | 12 ++++++++++-- src/LinkedIn.php | 19 ++++++++++--------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 1f82cda..9f2d601 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ phpunit.xml composer.lock vendor +.idea \ No newline at end of file diff --git a/src/Exceptions/LoginError.php b/src/Exceptions/LoginError.php index 0cb1b2e..5698ccc 100644 --- a/src/Exceptions/LoginError.php +++ b/src/Exceptions/LoginError.php @@ -29,6 +29,14 @@ public function __construct($name, $description) $this->description = $description; } + /** + * @return string + */ + public function getName() + { + return $this->name; + } + /** * @return string */ @@ -40,8 +48,8 @@ public function getDescription() /** * @return string */ - public function getName() + public function __toString() { - return $this->name; + return 'Name: ' . $this->getName() . ', Description: ' . $this->getDescription(); } } diff --git a/src/LinkedIn.php b/src/LinkedIn.php index 4e217d0..dbdc23c 100644 --- a/src/LinkedIn.php +++ b/src/LinkedIn.php @@ -277,7 +277,7 @@ protected function getUserFromAccessToken() try { return $this->api('GET', '/v1/people/~:(id,firstName,lastName,headline)'); } catch (LinkedInApiException $e) { - return; + return null; } } @@ -297,7 +297,7 @@ protected function getCode() if (isset($_REQUEST['code'])) { if ($storage->get('code') === $_REQUEST['code']) { //we have already validated this code - return; + return null; } //if stored state does not exists @@ -322,7 +322,7 @@ protected function getCode() return $_REQUEST['code']; } - return; + return null; } /** @@ -399,7 +399,7 @@ protected function fetchNewAccessToken() protected function getAccessTokenFromCode($code, $redirectUri = null) { if (empty($code)) { - return; + return null; } if ($redirectUri === null) { @@ -423,18 +423,18 @@ protected function getAccessTokenFromCode($code, $redirectUri = null) } catch (LinkedInApiException $e) { // most likely that user very recently revoked authorization. // In any event, we don't have an access token, so say so. - return; + return null; } if (empty($response)) { - return; + return null; } $tokenData = array_merge(array('access_token' => null, 'expires_in' => null), $response); $token = new AccessToken($tokenData['access_token'], $tokenData['expires_in']); if (!$token->hasToken()) { - return; + return null; } return $token; @@ -606,7 +606,7 @@ public function hasError() public function getError() { if (!$this->hasError()) { - return; + return null; } return new LoginError($_GET['error'], isset($_GET['error_description']) ? $_GET['error_description'] : null); @@ -659,7 +659,8 @@ protected function filterRequestOption(array &$options) switch ($options['format']) { case 'simple_xml': $options['simple_xml'] = true; - // simple_xml is still xml. This should fall through + $options['headers']['Content-Type'] = 'text/xml'; + break; case 'xml': $options['headers']['Content-Type'] = 'text/xml'; break; From c4e0ce9677982faf1cb01d24ab6a27600477dce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0rfan=20Evrens?= Date: Tue, 30 Jun 2015 07:28:24 +0300 Subject: [PATCH 2/3] removed .idea line --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9f2d601..7e2210e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ phpunit.xml composer.lock -vendor -.idea \ No newline at end of file +vendor \ No newline at end of file From 886cf0af2089a147f3aa5668d70d458a189e44d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0rfan=20Evrens?= Date: Wed, 1 Jul 2015 16:34:40 +0300 Subject: [PATCH 3/3] fix with php-cs-fixer --- src/Exceptions/LoginError.php | 2 +- src/Http/CurlRequest.php | 8 ++++---- src/Http/UrlGenerator.php | 8 ++++---- src/Http/UrlGeneratorInterface.php | 2 +- src/LinkedIn.php | 18 +++++++++--------- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Exceptions/LoginError.php b/src/Exceptions/LoginError.php index 5698ccc..3f17c50 100644 --- a/src/Exceptions/LoginError.php +++ b/src/Exceptions/LoginError.php @@ -50,6 +50,6 @@ public function getDescription() */ public function __toString() { - return 'Name: ' . $this->getName() . ', Description: ' . $this->getDescription(); + return 'Name: '.$this->getName().', Description: '.$this->getDescription(); } } diff --git a/src/Http/CurlRequest.php b/src/Http/CurlRequest.php index 7142fb2..05f8645 100644 --- a/src/Http/CurlRequest.php +++ b/src/Http/CurlRequest.php @@ -24,10 +24,10 @@ class CurlRequest implements RequestInterface public static $curlOptions = array( CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_RETURNTRANSFER => true, - CURLOPT_TIMEOUT => 60, - CURLOPT_USERAGENT => RequestInterface::USER_AGENT, - CURLOPT_VERBOSE => true, - CURLOPT_HEADER => true, + CURLOPT_TIMEOUT => 60, + CURLOPT_USERAGENT => RequestInterface::USER_AGENT, + CURLOPT_VERBOSE => true, + CURLOPT_HEADER => true, ); /** diff --git a/src/Http/UrlGenerator.php b/src/Http/UrlGenerator.php index dbb66b2..54e0061 100644 --- a/src/Http/UrlGenerator.php +++ b/src/Http/UrlGenerator.php @@ -22,12 +22,12 @@ class UrlGenerator implements UrlGeneratorInterface * Maps aliases to LinkedIn domains. */ public static $domainMap = array( - 'api' => 'https://api.linkedin.com/', - 'www' => 'https://www.linkedin.com/', + 'api' => 'https://api.linkedin.com/', + 'www' => 'https://www.linkedin.com/', ); /** - * @var boolean + * @var bool * * Indicates if we trust HTTP_X_FORWARDED_* headers. */ @@ -178,7 +178,7 @@ protected function getHttpProtocol() } /** - * @param boolean $trustForwarded + * @param bool $trustForwarded * * @return $this */ diff --git a/src/Http/UrlGeneratorInterface.php b/src/Http/UrlGeneratorInterface.php index e789d86..798fb17 100644 --- a/src/Http/UrlGeneratorInterface.php +++ b/src/Http/UrlGeneratorInterface.php @@ -33,7 +33,7 @@ public function getCurrentUrl(); /** * Should we trust forwarded headers? * - * @param boolean $trustForwarded + * @param bool $trustForwarded * * @return $this */ diff --git a/src/LinkedIn.php b/src/LinkedIn.php index dbdc23c..73ade48 100644 --- a/src/LinkedIn.php +++ b/src/LinkedIn.php @@ -246,7 +246,7 @@ protected function getUserFromAvailableData() $accessToken = $this->getAccessToken(); - /** + /* * This is true if both statements are true: * 1: We got an access token * 2: The access token has changed or if we don't got a user. @@ -277,7 +277,7 @@ protected function getUserFromAccessToken() try { return $this->api('GET', '/v1/people/~:(id,firstName,lastName,headline)'); } catch (LinkedInApiException $e) { - return null; + return; } } @@ -297,7 +297,7 @@ protected function getCode() if (isset($_REQUEST['code'])) { if ($storage->get('code') === $_REQUEST['code']) { //we have already validated this code - return null; + return; } //if stored state does not exists @@ -322,7 +322,7 @@ protected function getCode() return $_REQUEST['code']; } - return null; + return; } /** @@ -399,7 +399,7 @@ protected function fetchNewAccessToken() protected function getAccessTokenFromCode($code, $redirectUri = null) { if (empty($code)) { - return null; + return; } if ($redirectUri === null) { @@ -423,18 +423,18 @@ protected function getAccessTokenFromCode($code, $redirectUri = null) } catch (LinkedInApiException $e) { // most likely that user very recently revoked authorization. // In any event, we don't have an access token, so say so. - return null; + return; } if (empty($response)) { - return null; + return; } $tokenData = array_merge(array('access_token' => null, 'expires_in' => null), $response); $token = new AccessToken($tokenData['access_token'], $tokenData['expires_in']); if (!$token->hasToken()) { - return null; + return; } return $token; @@ -606,7 +606,7 @@ public function hasError() public function getError() { if (!$this->hasError()) { - return null; + return; } return new LoginError($_GET['error'], isset($_GET['error_description']) ? $_GET['error_description'] : null);