From 59f927af32baef5d8bd0b6c4127a5e28b0dcfd6e Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Sun, 29 Dec 2024 00:42:21 +0100 Subject: [PATCH] improve code style --- src/Connection.php | 19 +++++++++++-------- src/Exceptions/BaseException.php | 13 +++++++++++++ src/Exceptions/NoCredentialsException.php | 13 +++++++++++++ src/Klicktipp.php | 8 +++++--- 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index 574f345..7fe06cb 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -1,8 +1,10 @@ client = $this->client ?? + $this->client ??= new Client([ 'base_uri' => self::URL, 'headers' => [ 'Content-Type' => 'application/json', 'Accept' => 'application/json', - 'User-Agent' => self::USERAGENT.'/'.InstalledVersions::getVersion('d3/klicktipp-php-client') - ] + 'User-Agent' => self::USERAGENT.'/'.InstalledVersions::getVersion('d3/klicktipp-php-client'), + ], ]); return $this->client; @@ -91,12 +93,12 @@ class Connection * @param string $uri * @param array $options * @return ResponseInterface - * @throws BaseException|GuzzleException + * @throws BaseException */ public function request(string $method, string $uri, array $options = []): ResponseInterface { try { - $options['query'] = $options['query'] ?? []; + $options['query'] ??= []; $options[RequestOptions::COOKIES] = $this->getCookiesJar(); if (! empty($options['body'])) { @@ -114,6 +116,8 @@ class Connection $e->getResponse()->getStatusCode(), $e ); + } catch (GuzzleException $e) { + throw new BaseException($e->getMessage(), $e->getCode(), $e); } } @@ -123,7 +127,6 @@ class Connection * @param array $options * @return array * @throws BaseException - * @throws GuzzleException */ public function requestAndParse(string $method, string $uri, array $options = []): array { diff --git a/src/Exceptions/BaseException.php b/src/Exceptions/BaseException.php index c249cec..94a3578 100644 --- a/src/Exceptions/BaseException.php +++ b/src/Exceptions/BaseException.php @@ -1,5 +1,18 @@ + * @link https://www.oxidmodule.com + */ + namespace D3\KlicktippPhpClient\Exceptions; use Exception; diff --git a/src/Exceptions/NoCredentialsException.php b/src/Exceptions/NoCredentialsException.php index 75f7fd7..2964ce4 100644 --- a/src/Exceptions/NoCredentialsException.php +++ b/src/Exceptions/NoCredentialsException.php @@ -1,5 +1,18 @@ + * @link https://www.oxidmodule.com + */ + namespace D3\KlicktippPhpClient\Exceptions; class NoCredentialsException extends BaseException diff --git a/src/Klicktipp.php b/src/Klicktipp.php index 894cb03..dd63ee0 100644 --- a/src/Klicktipp.php +++ b/src/Klicktipp.php @@ -1,8 +1,10 @@ client_key = $client_key; $this->secret_key = $secret_key;