diff --git a/composer.json b/composer.json index 0eb1efd..679a23f 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,8 @@ ], "homepage": "https://github.com/zoonman/linkedin-api-php-client", "require": { - "php": ">=5.6", - "guzzlehttp/guzzle": "^6.3 || ^7.0" + "php": ">=7.3", + "guzzlehttp/guzzle": "^7.0" }, "license": "MIT", "authors": [ diff --git a/src/Client.php b/src/Client.php index 654ca5a..1a9537e 100644 --- a/src/Client.php +++ b/src/Client.php @@ -374,21 +374,23 @@ public static function responseToArray($response) $contents = ''; try { if ($contents = $response->getBody()->getContents()) { - $result = \GuzzleHttp\json_decode( + $result = \json_decode( $contents, - true + true, + 512, + \JSON_THROW_ON_ERROR ); } else if ($contents = $response->getHeaders()) { // Looks like when response body is empty the result might be in the headers. // Good job LinkedIn. $result = $contents; } - } catch (\Exception $exception) { + } catch (\Exception $ex) { throw new Exception( 'Invalid json response.', 'invalid-json-response', - $exception, - $exception->getMessage(), + $ex, + $ex->getMessage(), $contents ); } @@ -559,7 +561,7 @@ protected function buildUrl($endpoint, $params) * @param string $method * * @return array - * @throws \LinkedIn\Exception + * @throws Exception */ public function api($endpoint, array $params = [], $method = Method::GET) { @@ -667,8 +669,8 @@ public function upload($path) ]; try { $response = $guzzle->request(Method::POST, 'media/upload', $options); - } catch (RequestException $requestException) { - throw Exception::fromRequestException($requestException); + } catch (RequestException $ex) { + throw Exception::fromRequestException($ex); } return self::responseToArray($response); } @@ -682,7 +684,7 @@ protected function prepareOptions(array $params, $method) { $options = []; if ($method === Method::POST) { - $options['body'] = \GuzzleHttp\json_encode($params); + $options['body'] = \json_encode($params, \JSON_THROW_ON_ERROR); } return $options; }