99 * @package Default
1010 * @author Philipp Tkachev <philipp@zoonman.com>
1111 * @date 8/17/17 18:50
12- * @license http://www.zoonman.com/projects/linkedin-client/license.txt linkedin-client License
12+ * @license http://www.zoonman.com/projects/linkedin-client/license.txt
13+ * linkedin-client License
1314 * @version GIT: 1.0
1415 * @link http://www.zoonman.com/projects/linkedin-client/
1516 */
@@ -96,15 +97,17 @@ class Client
9697
9798 /**
9899 * List of default headers
100+ *
99101 * @var array
100102 */
101103 protected $ defaultApiHeaders = [
102104 'Content-Type ' => 'application/json ' ,
103- 'x-li-format ' => 'json '
105+ 'x-li-format ' => 'json ' ,
104106 ];
105107
106108 /**
107109 * Get list of headers
110+ *
108111 * @return array
109112 */
110113 public function getDefaultApiHeaders ()
@@ -114,6 +117,7 @@ public function getDefaultApiHeaders()
114117
115118 /**
116119 * Set list of default headers
120+ *
117121 * @param array $defaultApiHeaders
118122 *
119123 * @return Client
@@ -126,6 +130,7 @@ public function setDefaultApiHeaders($defaultApiHeaders)
126130
127131 /**
128132 * Obtain API root URL
133+ *
129134 * @return string
130135 */
131136 public function getApiRoot ()
@@ -135,6 +140,7 @@ public function getApiRoot()
135140
136141 /**
137142 * Specify API root URL
143+ *
138144 * @param string $apiRoot
139145 *
140146 * @return Client
@@ -147,6 +153,7 @@ public function setApiRoot($apiRoot)
147153
148154 /**
149155 * Get OAuth API root
156+ *
150157 * @return string
151158 */
152159 public function getOAuthApiRoot ()
@@ -156,6 +163,7 @@ public function getOAuthApiRoot()
156163
157164 /**
158165 * Set OAuth API root
166+ *
159167 * @param string $oAuthApiRoot
160168 *
161169 * @return Client
@@ -180,6 +188,7 @@ public function __construct($clientId = '', $clientSecret = '')
180188
181189 /**
182190 * Get ClientId
191+ *
183192 * @return string
184193 */
185194 public function getClientId ()
@@ -189,6 +198,7 @@ public function getClientId()
189198
190199 /**
191200 * Set ClientId
201+ *
192202 * @param string $clientId
193203 *
194204 * @return Client
@@ -201,6 +211,7 @@ public function setClientId($clientId)
201211
202212 /**
203213 * Get Client Secret
214+ *
204215 * @return string
205216 */
206217 public function getClientSecret ()
@@ -210,6 +221,7 @@ public function getClientSecret()
210221
211222 /**
212223 * Set Client Secret
224+ *
213225 * @param string $clientSecret
214226 *
215227 * @return Client
@@ -238,15 +250,15 @@ public function getAccessToken($code = '')
238250 self ::OAUTH2_RESPONSE_TYPE => $ code ,
239251 'redirect_uri ' => $ this ->getRedirectUrl (),
240252 'client_id ' => $ this ->getClientId (),
241- 'client_secret ' => $ this ->getClientSecret ()
253+ 'client_secret ' => $ this ->getClientSecret (),
242254 ];
243255 $ uri = $ this ->buildUrl ('accessToken ' , $ params );
244256 $ guzzle = new GuzzleClient ([
245- 'base_uri ' => $ this ->getOAuthApiRoot (),
246- 'headers ' => [
257+ 'base_uri ' => $ this ->getOAuthApiRoot (),
258+ 'headers ' => [
247259 'Content-Type ' => 'application/json ' ,
248- 'x-li-format ' => 'json '
249- ]
260+ 'x-li-format ' => 'json ' ,
261+ ],
250262 ]);
251263 try {
252264 $ response = $ guzzle ->get ($ uri );
@@ -320,17 +332,19 @@ protected function getCurrentScheme()
320332
321333 /**
322334 * Get current URL
335+ *
323336 * @return string
324337 */
325338 public function getCurrentUrl ()
326339 {
327- $ host = isset ($ _SERVER ['HTTP_HOST ' ]) ? $ _SERVER ['HTTP_HOST ' ] : 'localhost ' ;
328- $ path = isset ($ _SERVER ['REQUEST_URI ' ]) ? $ _SERVER ['REQUEST_URI ' ] : '/ ' ;
329- return $ this ->getCurrentScheme () .':// ' . $ host . $ path ;
340+ $ host = isset ($ _SERVER ['HTTP_HOST ' ]) ? $ _SERVER ['HTTP_HOST ' ] : 'localhost ' ;
341+ $ path = isset ($ _SERVER ['REQUEST_URI ' ]) ? $ _SERVER ['REQUEST_URI ' ] : '/ ' ;
342+ return $ this ->getCurrentScheme () . ':// ' . $ host . $ path ;
330343 }
331344
332345 /**
333346 * Get unique state or specified state
347+ *
334348 * @return string
335349 */
336350 public function getState ()
@@ -348,6 +362,7 @@ public function getState()
348362
349363 /**
350364 * Set State
365+ *
351366 * @param string $state
352367 *
353368 * @return Client
@@ -362,19 +377,20 @@ public function setState($state)
362377 * Retrieve URL which will be used to send User to LinkedIn
363378 * for authentication
364379 *
365- * @param array $scope Permissions that your application requires
380+ * @param array $scope Permissions that your application requires
366381 *
367382 * @return string
368383 */
369- public function getLoginUrl (array $ scope = array ('r_basicprofile ' , 'r_emailaddress ' ))
370- {
384+ public function getLoginUrl (
385+ array $ scope = ['r_basicprofile ' , 'r_emailaddress ' ]
386+ ) {
371387
372388 $ params = [
373389 'response_type ' => self ::OAUTH2_RESPONSE_TYPE ,
374390 'client_id ' => $ this ->getClientId (),
375391 'redirect_uri ' => $ this ->getRedirectUrl (),
376392 'state ' => $ this ->getState (),
377- 'scope ' => implode (' ' , $ scope )
393+ 'scope ' => implode (' ' , $ scope ),
378394 ];
379395 $ uri = $ this ->buildUrl ('authorization ' , $ params );
380396 return $ uri ;
@@ -414,7 +430,7 @@ public function setRedirectUrl($redirectUrl)
414430
415431 /**
416432 * @param string $endpoint
417- * @param array $params
433+ * @param array $params
418434 *
419435 * @return string
420436 */
@@ -438,20 +454,21 @@ protected function buildUrl($endpoint, $params)
438454
439455 /**
440456 * Perform API call to LinkedIn
457+ *
441458 * @param string $endpoint
442459 * @param array $params
443460 * @param string $method
444461 *
445462 * @return array
446463 * @throws \LinkedIn\Exception
447464 */
448- public function api ($ endpoint , array $ params = array () , $ method = Method::GET )
465+ public function api ($ endpoint , array $ params = [] , $ method = Method::GET )
449466 {
450467 $ headers = $ this ->getDefaultApiHeaders ();
451468 $ headers ['Authorization ' ] = 'Bearer ' . $ this ->accessToken ->getToken ();
452469 $ guzzle = new GuzzleClient ([
453470 'base_uri ' => $ this ->getApiRoot (),
454- 'headers ' => $ headers
471+ 'headers ' => $ headers,
455472 ]);
456473 $ uri = $ endpoint ;
457474 $ options = [];
@@ -498,35 +515,37 @@ public function api($endpoint, array $params = array(), $method = Method::GET)
498515 */
499516 private static function extractErrorDescription ($ json )
500517 {
501- if (isset ($ json ['error_description ' ])) {
502- return $ json ['error_description ' ];
503- } elseif (isset ($ json ['message ' ])) {
504- return $ json ['message ' ];
505- } else {
506- return null ;
507- }
518+ if (isset ($ json ['error_description ' ])) {
519+ return $ json ['error_description ' ];
520+ } elseif (isset ($ json ['message ' ])) {
521+ return $ json ['message ' ];
522+ } else {
523+ return null ;
524+ }
508525 }
509526
510527 /**
511528 * Make API call to LinkedIn using GET method
529+ *
512530 * @param string $endpoint
513- * @param array $params
531+ * @param array $params
514532 *
515533 * @return array
516534 */
517- public function get ($ endpoint , array $ params = array () )
535+ public function get ($ endpoint , array $ params = [] )
518536 {
519537 return $ this ->api ($ endpoint , $ params , Method::GET );
520538 }
521539
522540 /**
523541 * Make API call to LinkedIn using POST method
542+ *
524543 * @param string $endpoint
525- * @param array $params
544+ * @param array $params
526545 *
527546 * @return array
528547 */
529- public function post ($ endpoint , array $ params = array () )
548+ public function post ($ endpoint , array $ params = [] )
530549 {
531550 return $ this ->api ($ endpoint , $ params , Method::POST );
532551 }
0 commit comments