Skip to content

Commit e259a8f

Browse files
committed
♻️ refactored code
1 parent 25ad487 commit e259a8f

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/Fetch.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ public static function baseUrl($url)
186186

187187
/**
188188
* Base method for network requests
189+
* @throws \Exception
189190
*/
190191
public static function request($options)
191192
{
@@ -196,6 +197,7 @@ public static function request($options)
196197

197198
/**
198199
* Make a get request
200+
* @throws \Exception
199201
*/
200202
public static function get($url, $config = [])
201203
{
@@ -204,6 +206,7 @@ public static function get($url, $config = [])
204206

205207
/**
206208
* Make a post request
209+
* @throws \Exception
207210
*/
208211
public static function post($url, $data, $config = [])
209212
{
@@ -212,6 +215,7 @@ public static function post($url, $data, $config = [])
212215

213216
/**
214217
* Make a put request
218+
* @throws \Exception
215219
*/
216220
public static function put($url, $data, $config = [])
217221
{
@@ -220,6 +224,7 @@ public static function put($url, $data, $config = [])
220224

221225
/**
222226
* Make a patch request
227+
* @throws \Exception
223228
*/
224229
public static function patch($url, $data, $config = [])
225230
{
@@ -228,6 +233,7 @@ public static function patch($url, $data, $config = [])
228233

229234
/**
230235
* Make a delete request
236+
* @throws \Exception
231237
*/
232238
public static function delete($url, $config = [])
233239
{
@@ -236,12 +242,16 @@ public static function delete($url, $config = [])
236242

237243
/**
238244
* Make an options request
245+
* @throws \Exception
239246
*/
240247
public static function options($url, $config = [])
241248
{
242249
return static::request(array_merge($config, ["url" => $url, "method" => static::OPTIONS]));
243250
}
244251

252+
/**
253+
* @throws \Exception
254+
*/
245255
private static function call($request)
246256
{
247257
static::$handler = curl_init();
@@ -372,7 +382,7 @@ private static function call($request)
372382
*
373383
* @author Mashape (https://www.mashape.com)
374384
*/
375-
private static function parseHeaders($raw_headers)
385+
private static function parseHeaders(string $raw_headers): array
376386
{
377387
if (function_exists('http_parse_headers')) {
378388
return \http_parse_headers($raw_headers);
@@ -419,20 +429,16 @@ public static function getInfo($opt = false)
419429
/**
420430
* This function is useful for serializing multidimensional arrays, and avoid getting
421431
* the 'Array to string conversion' notice
422-
* @param array|object $data array to flatten.
432+
* @param array $data array to flatten.
423433
* @param bool|string $parent parent key or false if no parent
424434
* @return array
425435
*
426436
* @author Mashape (https://www.mashape.com)
427437
*/
428-
public static function buildHTTPCurlQuery($data, $parent = false)
438+
public static function buildHTTPCurlQuery(array $data, $parent = false): array
429439
{
430440
$result = array();
431441

432-
if (is_object($data)) {
433-
$data = get_object_vars($data);
434-
}
435-
436442
foreach ($data as $key => $value) {
437443
if ($parent) {
438444
$new_key = sprintf('%s[%s]', $parent, $key);
@@ -453,8 +459,9 @@ public static function buildHTTPCurlQuery($data, $parent = false)
453459

454460
/**
455461
* Shortcut method for making network requests.
456-
*
462+
*
457463
* @param array|string $options The url or request to hit.
464+
* @throws \Exception
458465
*/
459466
function fetch($options, $params = [])
460467
{

src/functions.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
if (!function_exists('fetch')) {
66
/**
77
* Shortcut method for making network requests.
8-
*
8+
*
99
* @param array|string $options The url or request to hit.
10+
* @throws Exception
1011
*/
1112
function fetch($options, $params = [])
1213
{

0 commit comments

Comments
 (0)