From 09416c4ce1461412ef22e3c5b31241413b01e06b Mon Sep 17 00:00:00 2001 From: Michael Gerdemann Date: Sat, 18 Jan 2020 09:18:45 +0100 Subject: [PATCH] fix: Filter only `null` values Creates an AbstractEndpoint to provide a method to filter only `null` values. --- Classes/Endpoint/AbstractEndpoint.php | 27 +++++++++++++++++++++++++++ Classes/Endpoint/Miscellaneous.php | 4 ++-- Classes/Endpoint/Repositories.php | 6 +++--- 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 Classes/Endpoint/AbstractEndpoint.php diff --git a/Classes/Endpoint/AbstractEndpoint.php b/Classes/Endpoint/AbstractEndpoint.php new file mode 100644 index 0000000..d69b432 --- /dev/null +++ b/Classes/Endpoint/AbstractEndpoint.php @@ -0,0 +1,27 @@ + $text, 'wiki' => $wiki ]; - $options['json'] = array_filter($options['json']); + $options['json'] = $this->removeNullValues($options['json']); $response = $this->client->request(self::BASE_URI . '/markdown', 'POST', $options); return (string)$response->getBody(); diff --git a/Classes/Endpoint/Repositories.php b/Classes/Endpoint/Repositories.php index 1b2b4dd..cf52e67 100644 --- a/Classes/Endpoint/Repositories.php +++ b/Classes/Endpoint/Repositories.php @@ -9,7 +9,7 @@ use Avency\Gitea\Client; /** * Repositories endpoint */ -class Repositories implements EndpointInterface +class Repositories extends AbstractEndpoint implements EndpointInterface { const BASE_URI = 'api/v1/repos'; @@ -79,7 +79,7 @@ class Repositories implements EndpointInterface ] ]; - $options['json'] = array_filter($options['json']); + $options['json'] = $this->removeNullValues($options['json']); $response = $this->client->request(self::BASE_URI . '/migrate', 'POST', $options); return \GuzzleHttp\json_decode($response->getBody(), true); } @@ -134,7 +134,7 @@ class Repositories implements EndpointInterface 'sort' => $sort, 'order' => $order, ]; - $options['query'] = array_filter($options['query']); + $options['query'] = $this->removeNullValues($options['query']); $response = $this->client->request(self::BASE_URI . '/search', 'GET', $options); return \GuzzleHttp\json_decode($response->getBody(), true); }