mirror of
https://github.com/avency/Gitea.git
synced 2025-10-29 10:42:33 +01:00
fix: Filter only null values
Creates an AbstractEndpoint to provide a method to filter only `null` values.
This commit is contained in:
27
Classes/Endpoint/AbstractEndpoint.php
Normal file
27
Classes/Endpoint/AbstractEndpoint.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Avency\Gitea\Endpoint;
|
||||
|
||||
use Avency\Gitea\Client;
|
||||
|
||||
/**
|
||||
* Abstract endpoint
|
||||
*/
|
||||
abstract class AbstractEndpoint implements EndpointInterface
|
||||
{
|
||||
/**
|
||||
* @param array $array
|
||||
* @return array
|
||||
*/
|
||||
protected function removeNullValues(array $array): array
|
||||
{
|
||||
return array_filter(
|
||||
$array,
|
||||
function($value) {
|
||||
return !is_null($value);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -9,7 +9,7 @@ use Avency\Gitea\Client;
|
||||
/**
|
||||
* Miscellaneous endpoint
|
||||
*/
|
||||
class Miscellaneous implements EndpointInterface
|
||||
class Miscellaneous extends AbstractEndpoint implements EndpointInterface
|
||||
{
|
||||
const BASE_URI = 'api/v1';
|
||||
|
||||
@ -41,7 +41,7 @@ class Miscellaneous implements EndpointInterface
|
||||
'text' => $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();
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user