Skip to content

Commit

Permalink
Merge pull request #1 from andriusbaliutis/master
Browse files Browse the repository at this point in the history
Make package compatible with PHP 8.3
  • Loading branch information
Bonscho authored Aug 2, 2024
2 parents f5e925d + 7375680 commit fa0cf13
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 81 deletions.
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
"Basic Auth",
"Client Certificate Auth"
],
"homepage": "http://chroma-x.de/",
"homepage": "https://chroma-x.de/",
"license": "MIT",
"authors": [
{
"name": "Martin Brecht-Precht",
"email": "[email protected]",
"homepage": "http://chroma-x.de"
"homepage": "https://chroma-x.de"
},
{
"name": "Andrius Baliutis",
"email": "[email protected]",
"homepage": "https://chroma-x.de"
}
],
"autoload": {
Expand All @@ -25,10 +30,10 @@
}
},
"require": {
"php": "^7.1 || ^8.3",
"php": "^8.3",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"chroma-x/basic-http-client": "~3.0"
"chroma-x/basic-http-client": "~4.0"
}
}
59 changes: 10 additions & 49 deletions src/JsonHttpClient.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace ChromaX\JsonHttpClient;

use ChromaX\BasicHttpClient\HttpClientInterface;
Expand All @@ -23,17 +25,9 @@
class JsonHttpClient implements HttpClientInterface
{

/**
* @var RequestInterface
*/
private $request;
private RequestInterface $request;

/**
* BasicHttpClient constructor.
*
* @param string $endpoint
*/
public function __construct($endpoint)
public function __construct(string $endpoint)
{
$url = new Url($endpoint);
$transport = new HttpTransport();
Expand All @@ -51,21 +45,15 @@ public function __construct($endpoint)
->setUrl($url);
}

/**
* @return RequestInterface
*/
public function getRequest(): RequestInterface
{
return $this->request;
}

/**
* @param string[] $queryParameters
* @return ResponseInterface
* @throws NetworkException
* @throws ConnectionTimeoutException
*/
public function get(array $queryParameters = array()): ResponseInterface
public function get(array $queryParameters = []): ResponseInterface
{
$this->request
->setMethod(RequestInterface::REQUEST_METHOD_GET)
Expand All @@ -77,11 +65,8 @@ public function get(array $queryParameters = array()): ResponseInterface

/**
* @param string[] $queryParameters
* @return ResponseInterface
* @throws NetworkException
* @throws ConnectionTimeoutException
*/
public function head(array $queryParameters = array()): ResponseInterface
public function head(array $queryParameters = []): ResponseInterface
{
$this->request
->setMethod(RequestInterface::REQUEST_METHOD_HEAD)
Expand All @@ -91,13 +76,7 @@ public function head(array $queryParameters = array()): ResponseInterface
return $this->request->getResponse();
}

/**
* @param array $postData
* @return ResponseInterface
* @throws NetworkException
* @throws ConnectionTimeoutException
*/
public function post(array $postData = array()): ResponseInterface
public function post(array $postData = []): ResponseInterface
{
$this->request
->getMessage()
Expand All @@ -108,13 +87,7 @@ public function post(array $postData = array()): ResponseInterface
return $this->request->getResponse();
}

/**
* @param array $putData
* @return ResponseInterface
* @throws NetworkException
* @throws ConnectionTimeoutException
*/
public function put(array $putData = array()): ResponseInterface
public function put(array $putData = []): ResponseInterface
{
$this->request
->getMessage()
Expand All @@ -125,13 +98,7 @@ public function put(array $putData = array()): ResponseInterface
return $this->request->getResponse();
}

/**
* @param array $patchData
* @return ResponseInterface
* @throws NetworkException
* @throws ConnectionTimeoutException
*/
public function patch(array $patchData = array()): ResponseInterface
public function patch(array $patchData = []): ResponseInterface
{
$this->request
->getMessage()
Expand All @@ -142,13 +109,7 @@ public function patch(array $patchData = array()): ResponseInterface
return $this->request->getResponse();
}

/**
* @param string[] $queryParameters
* @return ResponseInterface
* @throws NetworkException
* @throws ConnectionTimeoutException
*/
public function delete(array $queryParameters = array()): ResponseInterface
public function delete(array $queryParameters = []): ResponseInterface
{
$this->request
->setMethod(RequestInterface::REQUEST_METHOD_DELETE)
Expand Down
5 changes: 2 additions & 3 deletions src/Request/JsonRequest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace ChromaX\JsonHttpClient\Request;

use ChromaX\BasicHttpClient\Request\AbstractRequest;
Expand All @@ -14,9 +16,6 @@
class JsonRequest extends AbstractRequest
{

/**
* @return ResponseInterface
*/
protected function buildResponse(): ResponseInterface
{
return new JsonResponse($this);
Expand Down
19 changes: 4 additions & 15 deletions src/Request/Message/Body/JsonBody.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace ChromaX\JsonHttpClient\Request\Message\Body;

use ChromaX\BasicHttpClient\Exception\HttpRequestMessageException;
Expand All @@ -13,27 +15,14 @@
class JsonBody implements BodyInterface
{

/**
* @var array
*/
private $bodyData;
private array $bodyData;

/**
* Body constructor.
*
* @param array $bodyData
*/
public function __construct(array $bodyData)
{
$this->bodyData = $bodyData;
}

/**
* @param resource $curl
* @return $this
* @throws HttpRequestMessageException
*/
public function configureCurl($curl)
public function configureCurl(\CurlHandle $curl): self
{
$jsonBody = json_encode($this->bodyData);
if ($jsonBody === false) {
Expand Down
14 changes: 4 additions & 10 deletions src/Response/JsonResponse.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace ChromaX\JsonHttpClient\Response;

use ChromaX\BasicHttpClient\Exception\HttpResponseException;
Expand All @@ -13,12 +15,7 @@
class JsonResponse extends AbstractResponse
{

/**
* @param mixed $body
* @return $this
* @throws HttpResponseException
*/
protected function setBody($body)
protected function setBody(mixed $body): self
{
if ($this->getStatusCode() === 204) {
parent::setBody(null);
Expand All @@ -31,10 +28,7 @@ protected function setBody($body)
parent::setBody($body);
return $this;
}

/**
* @return array
*/

public function getBody(): array
{
return parent::getBody();
Expand Down

0 comments on commit fa0cf13

Please sign in to comment.